ListView item deletion not happening

  • Replies:1
Santhosh Billu
  • Forum posts: 1

Jul 6, 2015, 6:48:50 PM via Website

The aim is that store the string in the normal listview and then user touch(click) it move to next page along with user selected item. Once user click "Reject button" in the Operation.java, the should go-off from the List.java activity. It is not happening. It shows "Unfortunately, System has stopped".

MainActivity.java

publicstaticint loop_exute=0// first page variable
Intent i =newIntent(getApplicationContext(),List.class);
startActivity(i);

List.java

public classListextendsActionBarActivityimplementsOnItemClickListener{

privateListView mainListView ;privateArrayAdapter listAdapter ;
Button buttonSum;
staticString[] name;
ArrayList planetList =newArrayList();
int pos;

@Overrideprotectedvoid onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
mainListView =(ListView) findViewById( R.id.mainListView );

Bundle extras = getIntent().getExtras();

if(MainActivity.loop_exute==0)// acces 1st page value because the string array value sholuld load only once in its life time{

MainActivity.loop_exute=MainActivity.loop_exute+2;

name =newString[]{"AAA","BBB","CCC","DDD"};

planetList.addAll(Arrays.asList(name));

listAdapter =newArrayAdapter(this, R.layout.simplerow, planetList);

mainListView.setAdapter( listAdapter );

//mainListView.getChildAt(0).setBackgroundColor(Color.RED);

show();

}else// second time call {Intent intent = getIntent();if(intent.hasExtra("MESSAGE")){Bundle bd = getIntent().getExtras();if(!bd.getString("MESSAGE").equals(null)){Stringobject=bd.getString("MESSAGE");int pos=planetList.indexOf(object);
planetList.remove(pos);
listAdapter.notifyDataSetChanged();//show();}

}}}

publicvoid show(){
mainListView.setOnItemClickListener(newAdapterView.OnItemClickListener(){@Overridepublicvoid onItemClick(AdapterView arg0,View arg1,int position,long arg3)

{

Intent i =newIntent(getApplicationContext(),Operation.class);

i.putExtra("Value2",name[pos]);
startActivity(i);

}});

}

@Overridepublicboolean onCreateOptionsMenu(Menu menu){// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.list, menu);returntrue;}

@Overridepublicboolean onOptionsItemSelected(MenuItem item){// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if(id == R.id.action_settings){returntrue;}returnsuper.onOptionsItemSelected(item);}

@Overridepublicvoid onItemClick(AdapterView arg0,View arg1,int arg2,long arg3){// TODO Auto-generated method stub

}}

Operation.java

reject =(ImageButton) findViewById(R.id.imageButton2);
reject.setOnClickListener(newOnClickListener(){

@Overridepublicvoid onClick(View arg0){

Intent i =newIntent(getApplicationContext(),List.class);
i.putExtra("MESSAGE",value1);//send the list item value what we select in previous activity

startActivity(i);

}});

Reply
Juriy Bakunin
  • Forum posts: 2

Sep 24, 2015, 2:11:54 PM via Website

Try first make some changes in code formatting
classListextendsActionBarActivityimplementsOnItemClickListener - its very hard to read code without spaces

Reply