简体   繁体   中英

How to add edittext and button inside listview

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);
    }

}

How to add edittext and button inside listview

i want to add a button and edittext inside MainActivity class. how can i do that?

Please read this tutorial first: http://www.vogella.com/articles/AndroidListView/article.html . There is a section specifically of developing custom adapters which is what you want to do, but you need to have more information on how ListView works to understand it so I recommend reading the whole tutorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM