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);
}
}
如何在列表视图中添加edittext和按钮
我想在 MainActivity 类中添加一个按钮和edittext。我怎样才能做到这一点?