android string-array item使用,android – 从String-Array填充Listview

我有一个ListView,我通过String tutorialTitle1 = getResources().getString(R.string.tutorial1_title);填写它,但为了我的应用程序的目的和功能我别无选择,只能使用字符串数组

我从来没有使用String-Array,我想帮助实现ListView中的每个项目.目前我正是这样做的

public class tutorialActivity extends Activity{

String[] values;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.tutorial);

registerClickCallBack();

ListView listView = (ListView) findViewById(R.id.tutorialList);

String tutorialTitle1 = getResources().getString(R.string.tutorial1_title);

String tutorialTitle2 = getResources().getString(R.string.tutorial2_title);

String tutorialTitle3 = getResources().getString(R.string.tutorial3_title);

String tutorialTitle4 = getResources().getString(R.string.tutorial4_title);

String tutorialTitle5 = getResources().getString(R.string.tutorial5_title);

String tutorialTitle6 = getResources().getString(R.string.tutorial6_title);

String tutorialTitle7 = getResources().getString(R.string.tutorial7_title);

String tutorialTitle8 = getResources().getString(R.string.tutorial8_title);

String tutorialTitle9 = getResources().getString(R.string.tutorial9_title);

String tutorialTitle10 = getResources().getString(R.string.tutorial10_title);

String tutorialTitle11 = getResources().getString(R.string.tutorial11_title);

String tutorialTitle12 = getResources().getString(R.string.tutorial12_title);

String tutorialTitle13 = getResources().getString(R.string.tutorial13_title);

String tutorialTitle14 = getResources().getString(R.string.tutorial14_title);

values= new String[] { tutorialTitle1, tutorialTitle2, tutorialTitle3, tutorialTitle4, tutorialTitle5, tutorialTitle6, tutorialTitle7, tutorialTitle8, tutorialTitle9, tutorialTitle10, tutorialTitle11, tutorialTitle12, tutorialTitle13, tutorialTitle14};

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, values);

listView.setAdapter(adapter);

}

private void registerClickCallBack() {

ListView list = (ListView) findViewById(R.id.tutorialList);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView> parent, View viewClicked,int position, long id) {

Intent i = new Intent(viewClicked.getContext(), tutorialContentActivity.class);

i.putExtra("tutorialNumber", position);

startActivity(i);

}

});

}

}

但现在R.string.tutorial1_title不再存在,因为我已经说过了

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

Tutorial Content

所以我基本上如何用我的< string-array name =“tutorialTitle”>中的所有项目填充Listview.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值