我正在尝试我在网上看到的教程,该应用程序获取并显示来自服务器的JSONfeed,这部分工作正常,我试图在自定义列表视图中显示此提要但是当我尝试这样做时我得到了#34 ;尝试完成输入事件但输入事件接收器已经处理完毕" logcat中的错误,在app中没有任何反应,我有一个adpter类:
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;
}
}
我的主动:
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.
答案 0 :(得分:10)
在您的Public UserAdapter函数中,您的超级不会传入对象。
应该是:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource, objects);
this.context= context;
this.users_list= objects;
}
而不是:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource);
this.context= context;
this.users_list= objects;
}