I have two activities - MainActivity for user login page, and the second activity displaying user details(projects made by user) in a ListView. I want to create a Navigation Drawer Layout that will appear in both activities. I found the solution here. But the problem is, my second activity extends ListActivity to display user details in ListView, so I cannot extend anything else. here is my second activity:
public class ProjectList extends ListActivity {
ArrayList<String> listItems = new ArrayList<String>();
ArrayAdapter<String> adapter;
ListView listView;
JSONArray projects = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project_list_inflator);
listView = (ListView)findViewById(android.R.id.list);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
listView.setAdapter(adapter);
new HttpGetHandler().execute();
}
private class HttpGetHandler extends AsyncTask<String, Void, Void> {
String jsonUrl = "some url";
String imgUrl = "http://canvasflip.com/protected/app/elements/userElements/";
@Override
protected Void doInBackground(String... params) {
HttpGet httpGet = new HttpGet(jsonUrl);
//HttpGet httpGet1 = new HttpGet(imgUrl);
try {
HttpResponse httpResponse = MainActivity.httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream content = httpEntity.getContent();
String result = convertToString(content);
JSONObject jsonObject = new JSONObject(result);
projects = jsonObject.getJSONArray("projects");
ProjectList.this.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
for(int i = 0; i<projects.length(); i++) {
JSONObject p = projects.getJSONObject(i);
String title = p.getString("title");
listItems.add(title);
adapter.notifyDataSetChanged();
}
}catch(Exception e) {
Log.d("MSG", e.toString());
}
}
});
}catch(Exception e) {
System.out.println(e.getMessage());
}
return null;
}
public String convertToString(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine())!=null) {
result += line;
}
inputStream.close();
return result;
}
}
}