0
我想在單擊列表視圖後顯示帶有按鈕和Edittext的迷你表格。單擊列表視圖後顯示帶按鈕和Edittext的迷你表格
這是來自互聯網的代碼。如何在長按ListView項目後顯示帶有按鈕和文本框的簡單窗體。
我正在使用Android Studio。如果你想textBox
和按鈕顯示爲AlertDialog
或者要導航到另一個頁面的問題
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
// TODO Auto-generated method stub
//do what you want to do.
//If you want to delete that entry.
lv.remove(arg2);//where arg2 is position of item you click
myAdapter.notifyDataSetChanged();
return true;
}
});
現在:
public class sample extends Activity{
SimpleAdapter simpleAdpt;
private EditText pass;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
initList();
// We get the ListView component from the layout
ListView lv = (ListView) findViewById(R.id.listView);
simpleAdpt = new SimpleAdapter(this, planetsList, android.R.layout.simple_list_item_1, new String[] {"planet"}, new int[] {android.R.id.text1});
lv.setAdapter(simpleAdpt);
List<Map<String, String>> planetsList = new ArrayList<Map<String,String>>();
private void initList() {
planetsList.add(createPlanet("planet", "Mercury"));
planetsList.add(createPlanet("planet", "Venus"));
planetsList.add(createPlanet("planet", "Mars"));
planetsList.add(createPlanet("planet", "Jupiter"));
planetsList.add(createPlanet("planet", "Saturn"));
planetsList.add(createPlanet("planet", "Uranus"));
planetsList.add(createPlanet("planet", "Neptune"));
}
private HashMap<String, String> createPlanet(String key, String name) {
HashMap<String, String> planet = new HashMap<String, String>();
planet.put(key, name);
return planet;
}
唉唉我明白了,所以我需要做的是有一個警報框? – Paul
非常感謝,它給了我一個關於如何去做的想法。謝謝你:D – Paul
Sir Uma Kanth,我如何從列表視圖中刪除選定的listviewitem的ID或其位置,請給我示例代碼以供參考。提前致謝。 – Paul