2017-02-25 82 views
0

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

我当前的ListView

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

}

+0

在哪里添加两个按钮?到每个列表项目?或者只是两个按钮之外的列表视图,在布局中的一些地方? – Marat

+0

列表中每个项目的两个按钮 – Fanomezantsoa

+0

然后,您不应该使用'android.R.layout.simple_list_item_1'并需要创建一个自定义适配器,例如'BaseAdapter'。在网络上查找教程 – Marat

回答

相关问题