0

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。我怎样才能做到这一点?

4

1 回答 1

0

请先阅读本教程:http ://www.vogella.com/articles/AndroidListView/article.html 。有一节专门介绍了您想要做的开发自定义适配器,但您需要了解更多有关 ListView 如何工作的信息才能理解它,因此我建议阅读整个教程。

于 2013-09-28T17:35:24.003 回答