【问题标题】:How to add two buttons in listview如何在列表视图中添加两个按钮
【发布时间】:2017-07-16 13:07:29
【问题描述】:

我想在我的列表视图中添加两个按钮。 我的列表的两个按钮编辑和删除。 我已经浏览过关于这个主题的其他帖子,但我仍然不能:(。 我已经创建了一个自定义列表视图。 我是初学者,所以我很难理解。 这将是很好的一点帮助。 这是我的代码

我当前的列表视图

public class liste_offre extends AppCompatActivity {
DatabaseHelper myDb;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.liste_offre);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    ListView listView = (ListView) findViewById(R.id.List_offre);
    myDb = new DatabaseHelper(this);

    ArrayList<String> theList = new ArrayList<>();
    Cursor res = myDb.getAllData();
    if (res.getCount()==0){
        Toast.makeText(liste_offre.this,"Liste vide",Toast.LENGTH_LONG).show();
    }else {
        while (res.moveToNext()){
            theList.add(res.getString(1));
            ListAdapter listAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,theList);
            listView.setAdapter(listAdapter);
        }
    }
}

}

【问题讨论】:

  • 添加两个按钮在哪里?每个列表项?或者只是列表视图之外的两个按钮,有些在布局中?
  • 列表中每个项目的两个按钮
  • 那么你不应该使用android.R.layout.simple_list_item_1并且需要创建一个扩展的自定义适配器,例如BaseAdapter。在网上找教程
  • 我会努力的,我会告诉你它是否有效

标签: android


【解决方案1】:

请参考下面的帖子,它可能正是你想要的

ListView with Add and Delete Buttons in each Row in android

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 2015-11-18
    相关资源
    最近更新 更多