MainActivity.class:
public class MainActivity extends ListActivity {
public static final String TITLE = "title";
public static final String SUBTITLE = "subtitle";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/// setContentView(R.layout.activity_main);
setListAdapter(createAdapter());
}
protected Map<String, String> createElement(String title, String subtitle)
{
Map<String, String> result = new HashMap<String, String>();
result.put(TITLE, title);
result.put(SUBTITLE, subtitle);
return result;
}
public List<Map<String, String>> getData()
{
List<Map<String, String>> result = new ArrayList<Map<String,String>>();
result.add(createElement("Hello", ""));
result.add(createElement("Hello2", ""));
result.add(createElement("Hello3", ""));
return result;
}
public ListAdapter createAdapter()
{
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
android.R.layout.simple_list_item_2,
new String[]{TITLE, SUBTITLE, },
new int[]{android.R.id.text1, android.R.id.text2});
adapter.areAllItemsEnabled();
return adapter;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = null;
switch (position)
{
case 0:
i = new Intent(this, GalleryUrlActivity.class);
break;
case 1:
i = new Intent(this, GalleryFileActivity.class);
break;
case 2:
i = new Intent(this, SonEklenen.class );
break;
}
startActivity(i);
}
}
如何在listview中添加edittext和按钮
我想在MainActivity类中添加一个按钮和edittext。我怎么能这样做?
答案 0 :(得分:0)
请先阅读本教程:http://www.vogella.com/articles/AndroidListView/article.html。有一个专门用于开发自定义适配器的部分,这是你想要做的,但你需要有关于ListView如何理解它的更多信息,所以我建议阅读整个教程。