【发布时间】:2016-03-02 16:53:42
【问题描述】:
我正在尝试我在网上看到的教程,该应用程序从服务器获取并显示 JSONfeed,这部分工作正常,我正在尝试在自定义列表视图中显示此提要,但是当我尝试这样做时,我得到“尝试完成输入事件,但输入事件接收器已被处理”logcat 中的错误并且应用程序中没有任何反应,我有一个适配器类:
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;
}
}
我的 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.
【问题讨论】:
-
stackoverflow.com/questions/27588750/… 或许这里的答案会有所帮助
-
有很多关于这个的问题,但没有一个选择正确的答案,所以如果你解决了它,请发布你的答案。这是我找到的一个简短博客:laurivan.com/attempted-to-finish-an-input-event
-
仍然没有运气,不知道如何解决这个问题