Achal Mehra
Lurker
Hi all
am using a custom adapter for Listview to display the records fetched from database. However when listview activity loads after a couple of seconds it returns to the prior activity without loading listview.
Part of my main activity code is :
for (int i = 0; i < userArray.length(); i++) {
JSONObject jsonObject = userArray.getJSONObject(i);
oid = jsonObject.getInt("oid");
mobile = jsonObject.getString("mobile");
name = jsonObject.getString("name");
arr_oid = oid;
arr_mobile = mobile;
arr_name = name;
}
} else {
Toast.makeText(getApplicationContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
myorderadapter adapter = new myorderadapter(MyordersActivity.this, arr_name, arr_mobile,
arr_oid);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"this is click",Toast.LENGTH_SHORT).show();
}
});
}
}
//executing the async task
Myorderdetails ru = new Myorderdetails();
ru.execute();
}
custom adapter code is :
public class myorderadapter extends ArrayAdapter<String> {
Activity context;
String rname[];
String rmobile[];
int roid[];
Context c;
public myorderadapter(Activity context, String[] arr_name, String[] arr_mobile, int[] arr_oid) {
super(context, custom_myorder_table, arr_name);
this.context = context;
this.rname = arr_name;
this.rmobile = arr_mobile;
this.roid = arr_oid;
}
@NonNull
@override
public View getView(int position,View view, ViewGroup parent) {
View row = Inflater.inflate(custom_myorder_table, null, true);
TextView orderid = row.findViewById(R.id.lv_item_oid);
TextView custname = row.findViewById(R.id.lv_item_name);
TextView custmobile = row.findViewById(R.id.lv_item_mobile);
// now set our resources on views
orderid.setText(roid[position]);
custname.setText(rname[position]);
custmobile.setText(rmobile[position]);
return row;
};
}
App runs correctly and the listview screen displays the progress bar however before it could show listview populated with data, it simply returns to the previous screen.
am using a custom adapter for Listview to display the records fetched from database. However when listview activity loads after a couple of seconds it returns to the prior activity without loading listview.
Part of my main activity code is :
for (int i = 0; i < userArray.length(); i++) {
JSONObject jsonObject = userArray.getJSONObject(i);
oid = jsonObject.getInt("oid");
mobile = jsonObject.getString("mobile");
name = jsonObject.getString("name");
arr_oid = oid;
arr_mobile = mobile;
arr_name = name;
}
} else {
Toast.makeText(getApplicationContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
myorderadapter adapter = new myorderadapter(MyordersActivity.this, arr_name, arr_mobile,
arr_oid);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"this is click",Toast.LENGTH_SHORT).show();
}
});
}
}
//executing the async task
Myorderdetails ru = new Myorderdetails();
ru.execute();
}
custom adapter code is :
public class myorderadapter extends ArrayAdapter<String> {
Activity context;
String rname[];
String rmobile[];
int roid[];
Context c;
public myorderadapter(Activity context, String[] arr_name, String[] arr_mobile, int[] arr_oid) {
super(context, custom_myorder_table, arr_name);
this.context = context;
this.rname = arr_name;
this.rmobile = arr_mobile;
this.roid = arr_oid;
}
@NonNull
@override
public View getView(int position,View view, ViewGroup parent) {
View row = Inflater.inflate(custom_myorder_table, null, true);
TextView orderid = row.findViewById(R.id.lv_item_oid);
TextView custname = row.findViewById(R.id.lv_item_name);
TextView custmobile = row.findViewById(R.id.lv_item_mobile);
// now set our resources on views
orderid.setText(roid[position]);
custname.setText(rname[position]);
custmobile.setText(rmobile[position]);
return row;
};
}
App runs correctly and the listview screen displays the progress bar however before it could show listview populated with data, it simply returns to the previous screen.