• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help ListView item deletion not happening

ListView item deletion not happening

  • Related to Queries

    Votes: 0 0.0%
  • Sugession

    Votes: 0 0.0%

  • Total voters
    0
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<String> listAdapter ;
Button buttonSum;
staticString[] name;
ArrayList<String> planetList =newArrayList<String>();
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<String>(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);


}});
 
Back
Top Bottom