答案 0 :(得分:0)
public class Top extends ListActivity {
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
String[] rows = {1,2,3,4}; //This rows array Determine the no of rows to be displayed on the list
setContentView(R.layout.top);//layout for activity
setListAdapter(new MyAdapter(this, R.layout.top_list, R.id.topName, rows);
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId, String[] objects)
{
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View row = inflater.inflate(R.layout.top_list, parent, false); //top_list is the seperate layout that represents your list consider it has one TextView.
String[] rows = {1,2,3,4};
TextView tv = (TextView)findViewById(R.id.TextView1);
tv.setText(rows[position]);
return row;
}
}
}
1。扩展ListActivity而不是Activity 2.为活动创建两个布局,为列表创建另一个布局 3. rows数组确定listview中列表的no 4.该职位确定了清单编号。
我希望这有助于询问是否需要其他澄清。