2017-02-25 80 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

回答

相關問題