我已經發布過這個問題previous..but沒有得到任何建議thats爲什麼我再次發佈它..我有片段顯示它在ListView ..所以,我有(部分我的代碼):Android片段靜態方法不顯示列表視圖項目
public class TwoFragment extends Fragment {
Button btn1;
static ListView listview;
ProgressDialog mProgressDialog;
static Activity activity;
public TwoFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_two2, container, false);
activity = getActivity();
listview = (ListView) view.findViewById(R.id.listview);
return view;
}
public static void display(final String serverResponse) {
@SuppressWarnings("unused")
final class DownloadJSON extends AsyncTask<String, String, Void> {
private JSONObject jsonobject;
private JSONArray jsonarray;
private ListViewAdapter adapter;
private ArrayList<HashMap<String, String>> arraylist;
@Override
protected Void doInBackground(String... params) {
try {
jsonarray = new JSONArray(serverResponse);
Gson gson = new Gson();
User[] user = gson.fromJson(jsonarray.toString(), User[].class);
for (int i = 0; i < user.length; i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", user[i].getFullname());
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
adapter = new ListViewAdapter(activity, arraylist);
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
}
}
在這段代碼中,我沒有得到裏面的ListView任何顯..
把你的適配器代碼和你從哪裏調用這個方法。 –
你在哪裏調用「顯示」方法? – Raghavendra
我正在使用tablayout..so.display方法將自動從mainActivity調用.. – Preeti