我有两种语言的两个文本文件。我需要我的代码从textfile 1和textfile 2读取一行,并将它们放在listview中,它有两个textview。我怎么能这样做?
我的代码在这里:
public class ListViewSoore extends ListActivity{
ArrayAdapter<String> adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view);
String itemsen[]=getResources().getStringArray(R.row.pa1);
adapter=new MyAdapter(this, android.R.layout.simple_list_item_1, R.id.textView1,itemsen);
setListAdapter(adapter);
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId, String[] strings) {
super(context, resource, textViewResourceId, strings);
}
@Override
public View getView(int position,View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.list_item, parent, false);
String itemsen[]=getResources().getStringArray(R.row.pa1);
String itemsti[]=getResources().getStringArray(R.row.pa2);
TextView tven=(TextView) row.findViewById(R.id.textView1);
TextView tvti=(TextView) row.findViewById(R.id.textView2);
tven.setText(itemsen[position]);
tvti.setText(itemsti[position]);
return row;
}
}
答案 0 :(得分:1)
我可能对您要完成的任务有点不确定,但在strings.xml文件中定义了String数组值。
作为rescource包含的字符串数组应该如下所示(在strings.xml文件中):
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>