2.4.9 列表视图
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/listView2" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout>
public class MainActivity extends Activity { private int status = 0; private String[] books2 = new String[] { "乖,摸摸头", "从你的全世界路过", "杜拉拉升职记" }; private String[] author = new String[] { "大冰","张嘉佳","xxx"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.listView2); int[] to = new int[]{R.id.textView1,R.id.textView2}; List<Map<String,Object>> data = new ArrayList<Map<String, Object>>(); for(int i=0;i<books2.length;i++){ Map<String,Object> newMap = new HashMap<String, Object>(); newMap.put("author", this.author[i]); newMap.put("book", this.books2[i]); data.add(newMap); } SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.activity_main, new String[]{"book","author"}, to); listView.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
本篇文章首发自魔芋红茶的博客https://www.cnblogs.com/Moon-Face/
请尊重其他人的劳动成功,转载请注明。