I am trying out a Tutorial i saw online,The app Gets and displays JSONfeed from server,this part works correctly,i am trying to display this feed in Custom listview but when i try to do so i get the "Attempted to finish an input event but the input event receiver has already been disposed" error in logcat and nothing happens in app,i have an adpter class:
public class UserAdapter extends ArrayAdapter<UserData>{
private Context context;
private List<UserData> users_list;
public UserAdapter(Context context, int resource,List<UserData> objects) {
super(context, resource);
this.context= context;
this.users_list= objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customview= inflater.inflate(R.layout.item_user, parent, false);
UserData userData= users_list.get(position);
TextView tv = (TextView) customview.findViewById(R.id.textview1);
tv.setText(userData.getName());
return customview;
}
}
My MainAtivity:
import android.app.ListActivity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ListActivity {
List<MyTask> tasks;
List<UserData> userDataList;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
userDataList= new ArrayList<>();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.ac) {
if (isOnline()) {
requestData("http://192.168.1.4/database/getInfoDroid.php");
} else {
Toast.makeText(MainActivity.this, "Network Unavailable", Toast.LENGTH_LONG).show();
}
return true;
}
return super.onOptionsItemSelected(item);
}
private void requestData(String uri) {
MyTask task=new MyTask();
task.execute(uri);
}
protected void updateDisplay(){
UserAdapter adapter= new UserAdapter(this,R.layout.item_user,userDataList);
setListAdapter(adapter);
}
protected boolean isOnline(){
ConnectivityManager cm= (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo netinfo= cm.getActiveNetworkInfo();
if(netinfo!= null && netinfo.isConnectedOrConnecting()){
return true;
}
else {
return false;
}
}
private class MyTask extends AsyncTask {
@Override
protected void onPreExecute() {
}
@Override
protected Object doInBackground(Object[] objects) {
System.out.print("Do in background ");
String content =HttpManager.getData(objects[0].toString());
System.out.print(content);
return content;
}
@Override
protected void onPostExecute(Object o) {
if (o.toString()==null){
Toast.makeText(MainActivity.this,"Cant connect to Web",Toast.LENGTH_LONG).show();
}
userDataList= UserDataJsonParser.parseFeed(o.toString());
System.out.print(userDataList);
updateDisplay();
}
@Override
protected void onProgressUpdate(Object[] values) {
//updateDisplay(values[0].toString());
}
}
}
LogCat:
11-28 20:50:12.115 28063-28078/hilz.myapplication W/EGL_emulation: eglSurfaceAttrib not implemented
11-28 20:50:12.115 28063-28078/hilz.myapplication W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa50c8260, error=EGL_SUCCESS
11-28 20:50:13.287 28063-28063/hilz.myapplication W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
In your Public UserAdapter function, your super is not passing in the Objects.
It should be:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource, objects);
this.context= context;
this.users_list= objects;
}
and not:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource);
this.context= context;
this.users_list= objects;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With