ListView in Fragment not displayed in MainActivity - android

I am getting data from this API and have parsed it into a listview within a fragment. However, I can't seem to get it displayed on the Main Activity. Can anyone point me in the right direction please?
EDIT1: The layout files can be found here.
Main Activity:
package com.example.szen95.meddict;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#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);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
SearchFragment:
package com.example.szen95.meddict;
import android.app.ListFragment;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class SearchFragment extends ListFragment {
//
// #Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search_fragment);
// if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
// .add(R.id.container, new SearchFragment())
// .commit();
// }
// }
private ProgressDialog pDialog;
// URL to get contacts JSON
private static String url = "http://dailymed.nlm.nih.gov/dailymed/services/v2/drugclasses.json";
// JSON Node names
private static final String TAG_DATA = "data";
private static final String TAG_CODE = "code";
private static final String TAG_CODING_SYSTEM = "codingsystem";
private static final String TAG_TYPE = "type";
private static final String TAG_NAME = "name";
// contacts JSONArray
JSONArray data = null;
// Hashmap for ListView
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>();
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
// Retrieving the currently selected item number
int position = getArguments().getInt("position");
// Creating view correspoding to the fragment
View v = inflater.inflate(R.layout.activity_search_fragment, container, false);
// Updating the action bar title
// getActivity().getActionBar().setTitle(options[position]);
// Calling async task to get json
new GetData().execute();
return v;
}
/**
* Async task class to get json by making HTTP call
* */
private class GetData extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
//
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
data = jsonObj.getJSONArray(TAG_DATA);
// looping through All Contacts
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String code = c.getString(TAG_CODE);
String codingsystem = c.getString(TAG_CODING_SYSTEM);
String type = c.getString(TAG_TYPE);
String name = c.getString(TAG_NAME);
;
// tmp hashmap for single contact
HashMap<String, String> data = new HashMap<String, String>();
// adding each child node to HashMap key => value
data.put(TAG_CODE, code);
data.put(TAG_CODING_SYSTEM, codingsystem);
data.put(TAG_TYPE, type);
data.put(TAG_NAME, name);
// adding contact to contact list
dataList.add(data);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
SimpleAdapter adapter = new SimpleAdapter(getActivity(), dataList,
R.layout.list_item, new String[] { TAG_NAME, TAG_CODE}, new int[] { R.id.name,
R.id.code});
setListAdapter(adapter);
}
}
}

Un comment the onCreate method in searchFragment because your fragment is not inflating any layout

Fragments can be put into a layout using FragmentManager.
Add replace onCreate of your MainActivity with following.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fts = fragmentManager.beginTransaction();
Fragment fragment = new SearchFragment();
String fragmentTag = "SearchFragment";
fts.add(R.id.main_container, fragment, fragmentTag);
fts.commit();
}
Change your layout_activity_main.xml to following. You don't need a listview here. Just make sure you have a layout container main_container to place your fragment in.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<!-- Main ListView
Always give id value as list(#android:id/list)
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null"/>
-->
</LinearLayout>

I think your problem is caused by Jason parsing.
private static final String TAG_CODING_SYSTEM = "codingSystem";
Jason key is case sensitive. But please try to debug by yourself next time, it's the only way to become a better coder. Cheers!

Related

search in an listview using a Searchview on the action bar

i have an activity that list clients on a listview from a sql server database, and i've had implement the searchview.. but i dont know how to implement the query to search the client names from the listview.. can someone help me??
here is my the code from the activity where is the list:
package com.example.hp13_b200.testedesign;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class listar_clientes extends ActionBarActivity {
private ListView list;
private TextView nome, abv, esaldo, telefone, mail, morada;
private SearchView search;
private ProgressDialog pDialog;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_listar_clientes, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
// Associate searchable configuration with the SearchView
}
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://ciemarco.dyndns.org:90/androidapp/listar_clientes.php";
// JSON Node names
private static final String TAG_CLIENTE= "clientes";
private static final String TAG_NOME = "nome";
private static final String TAG_ABV = "nome2";
private static final String TAG_SALDO = "esaldo";
private static final String TAG_TELEFONE = "telefone";
private static final String TAG_MORADA = "morada";
private static final String TAG_MAIL = "email";
// products JSONArray
JSONArray products = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listar_clientes);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
/*if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}*/
nome = (TextView)findViewById(R.id.name);
abv = (TextView)findViewById(R.id.abv);
telefone = (TextView)findViewById(R.id.telefone);
morada = (TextView)findViewById(R.id.morada);
mail = (TextView)findViewById(R.id.mail);
esaldo = (TextView)findViewById(R.id.esaldo);
list = (ListView)findViewById(android.R.id.list);
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
// Log.v("COUNT-->",productsList.get(0).toString());
// Get listview
/* list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// getting values from selected ListItem
String nome = ((TextView) view.findViewById(R.id.name)).getText()
.toString();
Log.d("Cod_conta: ", ""+nome);
// Starting new intent
Intent in = new Intent(listar_clientes.this,
detalhes_cliente.class);
// sending pid to next activity
in.putExtra(TAG_NOME, nome);
//in.putExtra(TAG_ABV, abv);
Log.d("entrou: ", "vai entrar");
//startActivityForResult(in,100);
// starting new activity and expecting some response back
startActivity(in);
}
} );*/
// launching Edit Product Screen
// lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//
//
// // Starting new intent
// Intent in = new Intent(getApplicationContext(),
// list_item.class);
// // sending pid to next activity
// in.putExtra(TAG_PID, pid);
//
// // starting new activity and expecting some response back
// startActivityForResult(in, 100);
// }
// });
/* ListAdapter adapter = new SimpleAdapter(
encomendas_user.this, productsList,
R.layout.activity_list_item, new String[] { TAG_IDUSER,
TAG_TITULO},
new int[] { R.id.pid, R.id.name });
// updating listview
setListAdapter(adapter);*/
// on seleting single product
// launching Edit Product Screen
}
// Response from Edit Product Activity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(listar_clientes.this);
pDialog.setMessage("A Carregar dados. Por favor Aguarde...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
// int success = json.getInt(TAG_IDUSER);
//Log.d("NAMSUCCESSE: ", ""+success);
//if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_CLIENTE);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String name = c.getString(TAG_NOME);
String abv = c.getString(TAG_ABV);
String telefone = c.getString(TAG_TELEFONE);
String morada = c.getString(TAG_MORADA);
String mail = c.getString(TAG_MAIL);
String esaldo = c.getString(TAG_SALDO);
Log.d("NAME TESTE: ", name);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_NOME, name);
map.put(TAG_ABV, abv);
map.put(TAG_TELEFONE, telefone);
map.put(TAG_MORADA, morada);
map.put(TAG_MAIL, mail);
map.put(TAG_SALDO, esaldo);
// if(UserInfo.userID==(Integer.parseInt(name))){
// adding HashList to ArrayList
productsList.add(map);
// }
}
/* } else {
// no products found
// Launch Add New product Activity
//Intent i = new Intent(getApplicationContext(),
// NewProductActivity.class);
// Closing all previous activities
//i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(i);
}*/
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
listar_clientes.this, productsList,
R.layout.activity_list_item_clientes, new String[]{TAG_NOME, TAG_MAIL, TAG_TELEFONE, TAG_MORADA, TAG_SALDO},
new int[]{R.id.name, R.id.mail, R.id.telefone, R.id.morada, R.id.esaldo});
// updating listview
list.setAdapter(adapter);
}
});
}
}
public void listar(View v){
LinearLayout vwParentRow = (LinearLayout)v.getParent();
TextView nome=(TextView)vwParentRow.getChildAt(1);
TextView telefone=(TextView)vwParentRow.getChildAt(4);
TextView morada=(TextView)vwParentRow.getChildAt(3);
TextView mail=(TextView)vwParentRow.getChildAt(5);
TextView esaldo=(TextView)vwParentRow.getChildAt(6);
// Starting new intent
Intent in = new Intent(getApplicationContext(),
detalhes_cliente.class);
// sending pid to next activity
in.putExtra(TAG_NOME, nome.getText().toString());
in.putExtra(TAG_TELEFONE, telefone.getText().toString());
in.putExtra(TAG_MORADA, morada.getText().toString());
in.putExtra(TAG_MAIL, mail.getText().toString());
in.putExtra(TAG_SALDO, esaldo.getText().toString());
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item= menu.findItem(R.id.action_settings);
item.setVisible(false);
super.onPrepareOptionsMenu(menu);
return true;
}
}
and here is the code from the searchresultactivity:
package com.example.hp13_b200.testedesign;
import android.app.SearchManager;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SearchResultsActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_results);
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
//use the query to search your data somehow
}
}
#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_search_results, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Regarding the Model-View-Controller approach, all you need to do is create a model with the data that matches your search and hand it tho the view (your list view) that will display it.
You probably want a setOnQueryTextListener which can filter your results when text is written in SearchView.
There is an existing post explaining this quite well, Implementing SearchView in action bar.

Error: Content view not yet created

I'm new to Android development and I have a problem with setting up getting into the next activity when I click an item in my listview within my ListFragment.
When I compile and run the app, it crashes with the error: Content view not yet created. Here is the relevant code. Any help would be much appreciated!
MainActivity:
package com.example.szen95.meddict;
import android.app.SearchManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.SearchView;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new SearchFragment())
.commit();
}
getSupportActionBar().setElevation(0f);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService( Context.SEARCH_SERVICE );
SearchView searchView = (SearchView) menu.findItem( R.id.search_bar ).getActionView();
searchView.setSearchableInfo( searchManager.getSearchableInfo( getComponentName() ) );
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return super.onOptionsItemSelected(item);
}
}
SearchFragment:
package com.example.szen95.meddict;
/**
* Created by szen95 on 6/15/15.
*/
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
/**
* A placeholder fragment containing a simple view.
*/
public class SearchFragment extends ListFragment {
private ProgressDialog pDialog;
// URL to get contacts JSON
private static String url = "http://dailymed.nlm.nih.gov/dailymed/services/v2/drugclasses.json";
// JSON Node names
private static final String TAG_DATA = "data";
private static final String TAG_CODE = "code";
private static final String TAG_CODING_SYSTEM = "codingSystem";
private static final String TAG_TYPE = "type";
private static final String TAG_NAME = "name";
// contacts JSONArray
JSONArray data = null;
// ArrayAdapter<String> mConditionsAdapter;
public SearchFragment() {
}
ArrayList<HashMap<String, String>> dataList;
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
dataList = new ArrayList<HashMap<String, String>>();
// Creating view correspoding to the fragment
View v = inflater.inflate(R.layout.fragment_main, container, false);
ListView lv = getListView();
// Listview on item click listener
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String name = ((TextView) view.findViewById(R.id.name))
.getText().toString();
String code = ((TextView) view.findViewById(R.id.code))
.getText().toString();
// Starting single contact activity
Intent in = new Intent(getActivity().getApplicationContext(),
Details.class);
in.putExtra(TAG_NAME, name);
in.putExtra(TAG_CODE, code);
startActivity(in);
}
});
new GetData().execute();
return v;
}
/**
* Async task class to get json by making HTTP call
* */
private class GetData extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
//
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
data = jsonObj.getJSONArray(TAG_DATA);
// looping through All Contacts
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String code = c.getString(TAG_CODE);
String codingSystem = c.getString(TAG_CODING_SYSTEM);
String type = c.getString(TAG_TYPE);
String name = c.getString(TAG_NAME);
// tmp hashmap for single contact
HashMap<String, String> data = new HashMap<String, String>();
// adding each child node to HashMap key => value
data.put(TAG_CODE, code);
data.put(TAG_CODING_SYSTEM, codingSystem);
data.put(TAG_TYPE, type);
data.put(TAG_NAME, name);
// adding contact to contact list
dataList.add(data);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
SimpleAdapter adapter = new SimpleAdapter(getActivity(), dataList,
R.layout.list_item_search, new String[] { TAG_NAME, TAG_CODE}, new int[] { R.id.name,
R.id.code});
setListAdapter(adapter);
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
//
// #Override
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// inflater.inflate(R.menu.menu_main, menu);
//
//
// }
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_about) {
// FetchDataTask defTask = new FetchDataTask();
// defTask.execute();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Details:
package com.example.szen95.meddict;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.TextView;
public class Details extends ActionBarActivity {
// JSON node keys
private static final String TAG_NAME = "name";
private static final String TAG_CODE = "code";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
// getting intent data
Intent in = getIntent();
// Get JSON values from previous intent
String name = in.getStringExtra(TAG_NAME);
String code = in.getStringExtra(TAG_CODE);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCode = (TextView) findViewById(R.id.code_label);
lblName.setText(name);
lblCode.setText(code);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return onCreateOptionsMenu(menu);
}
}
SearchFragment extends ListFragment. In a ListFragment, getListView() cannot be called in onCreateView(), because onCreateView() is creating the fragment's content view and has not yet completed. The call to getListView() in SearchFragment is the cause of the exception.
Move the the call to getListView() and related to code to one of the fragment lifecycle methods that is called after onCreateView(), such as onViewCreated() or onActivityCreate(). For example:
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
ListView lv = getListView();
// Listview on item click listener
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String name = ((TextView) view.findViewById(R.id.name))
.getText().toString();
String code = ((TextView) view.findViewById(R.id.code))
.getText().toString();
// Starting single contact activity
Intent in = new Intent(getActivity().getApplicationContext(),
Details.class);
in.putExtra(TAG_NAME, name);
in.putExtra(TAG_CODE, code);
startActivity(in);
}
});
}

MainActivity not populated with data from listview

I am trying to populate my listview from this API.
There are no errors when I compile and run the app, but there is just a blank MainActivity. Here is my code for my project.
Main Activity:
package com.example.szen95.meddict;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new SearchFragment())
.commit();
}
getSupportActionBar().setElevation(0f);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
SearchFragment:
package com.example.szen95.meddict;
/**
* Created by szen95 on 6/15/15.
*/
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
/**
* A placeholder fragment containing a simple view.
*/
public class SearchFragment extends Fragment {
private ProgressDialog pDialog;
// URL to get contacts JSON
private static String url = "http://dailymed.nlm.nih.gov/dailymed/services/v2/drugclasses.json";
// JSON Node names
private static final String TAG_DATA = "data";
private static final String TAG_CODE = "code";
private static final String TAG_CODING_SYSTEM = "codingSystem";
private static final String TAG_TYPE = "type";
private static final String TAG_NAME = "name";
// contacts JSONArray
JSONArray data = null;
// ArrayAdapter<String> mConditionsAdapter;
public SearchFragment() {
}
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>();
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
// Retrieving the currently selected item number
// int position = getArguments().getInt("position");
// Creating view correspoding to the fragment
View v = inflater.inflate(R.layout.fragment_main, container, false);
new GetData().execute();
return v;
}
/**
* Async task class to get json by making HTTP call
* */
private class GetData extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
//
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
data = jsonObj.getJSONArray(TAG_DATA);
// looping through All Contacts
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String code = c.getString(TAG_CODE);
String codingSystem = c.getString(TAG_CODING_SYSTEM);
String type = c.getString(TAG_TYPE);
String name = c.getString(TAG_NAME);
// tmp hashmap for single contact
HashMap<String, String> data = new HashMap<String, String>();
// adding each child node to HashMap key => value
data.put(TAG_CODE, code);
data.put(TAG_CODING_SYSTEM, codingSystem);
data.put(TAG_TYPE, type);
data.put(TAG_NAME, name);
// adding contact to contact list
dataList.add(data);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
SimpleAdapter adapter = new SimpleAdapter(getActivity(), dataList,
R.layout.list_item_search, new String[] { TAG_NAME, TAG_CODE}, new int[] { R.id.name,
R.id.code});
setListAdapter(adapter);
}
}
private void setListAdapter(SimpleAdapter adapter) {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_main, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
// FetchDataTask defTask = new FetchDataTask();
// defTask.execute();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Below two things will fix your problem -
Extend your fragment by ListFragment not with Fragment.
Delete below method.
private void setListAdapter(SimpleAdapter adapter) {
}

I am trying to change the url for json parsing in my app on every click of option in settings menu

When the code is run it loads news only of india even after selecting another option in the Settings Menu. Can someone please tell me the error?
Main Activity:
package com.example.user.s;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends ListActivity
{
private ProgressDialog pDialog;
// URL to get contacts JSON
private static String url;
public String servername;
private static final String TAG_ARTICLES="articles";
private static final String TAG_PUBLISH_DATE = "publish_date";
private static final String TAG_SOURCE = "source";
private static final String TAG_SUMMARY = "summary";
private static final String TAG_TITLE = "title";
private static final int RESULT_SETTINGS = 1;
JSONArray articles = null;
// Hashmap for ListView
ArrayList<HashMap<String, String>> articleList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
articleList = new ArrayList<HashMap<String, String>>();
ListView lv = getListView();
// Listview on item click listener
/* // Starting single contact activity
Intent in = new Intent(getApplicationContext(),
SingleContactActivity.class);
in.putExtra(TAG_PUBLISH_DATE, date);
in.putExtra(TAG_SOURCE, source);
in.putExtra(TAG_SUMMARY, desc);
in.putExtra(TAG_TITLE,ttle);
startActivity(in);*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
Intent i = new Intent(this, setting.class);
startActivityForResult(i, RESULT_SETTINGS);
break;
}
return true;
}
private void update() {
GetContacts weatherTask = new GetContacts();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
String location = prefs.getString(getString(R.string.country_preference),
getString(R.string.country_default));
if(location.equals("India"))
url="http://api.feedzilla.com/v1/categories/19/subcategories/888/articles.json?count=10";
else
url="http://api.feedzilla.com/v1/categories/19/subcategories/890/articles.json?count=10";
weatherTask.execute();
}
#Override
public void onStart() {
super.onStart();
update();
}
private class GetContacts extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(Void... params) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
articles = jsonObj.getJSONArray(TAG_ARTICLES);
// looping through All Contacts
for (int i = 0; i < articles.length(); i++) {
JSONObject c = articles.getJSONObject(i);
String id = c.getString(TAG_PUBLISH_DATE);
String name = c.getString(TAG_SOURCE);
String email = c.getString(TAG_SUMMARY);
String ttle = c.getString(TAG_TITLE);
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
contact.put(TAG_PUBLISH_DATE, id);
contact.put(TAG_SOURCE, name);
contact.put(TAG_SUMMARY, email);
contact.put(TAG_TITLE, ttle);
// adding contact to contact list
articleList.add(contact);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, articleList,
R.layout.row, new String[]{TAG_PUBLISH_DATE, TAG_SOURCE,
TAG_SUMMARY}, new int[]{R.id.publish_date,
R.id.src, R.id.summary});
setListAdapter(adapter);
}
}
}
Settings Activity:
package com.example.user.s;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class setting extends PreferenceActivity {
private static final String COUNTRIES = "countries";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
}
}
preference.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Country">
<ListPreference
android:key="country_preference"
android:title="#string/country_preference"
android:summary="Choose your Country"
android:entries="#array/entries_transport_list_preference"
android:entryValues="#array/entryvalues_transport_list_preference"
/>
</PreferenceCategory>
</PreferenceScreen>
array.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="entries_transport_list_preference">
<item>India</item>
<item>China</item>
<item>Japan</item>
</string-array>
<string-array name="entryvalues_transport_list_preference">
<item>India</item>
<item>China</item>
<item>3</item>
</string-array>``
</resources>
You should call update() in onResume instead onStart
#Override
public void onResume() {
super.onResume();
update();
}

Android: Convert ListActivity into ListFragment?

Hello I am using the tutorial from androidhive for working with MySQL and so on.
I want to use the following activity as a fragment - but I have to transfer the ListActivity into ListFragment - when I just change the extend from ListActivity to ListFragment different error appear
AllProductsActivity.java
package com.example.androidhive;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class AllProductsActivity extends ListActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://api.androidhive.info/android_connect/get_all_products.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_PID = "pid";
private static final String TAG_NAME = "name";
// products JSONArray
JSONArray products = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_products);
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
// Get listview
ListView lv = getListView();
// on seleting single product
// launching Edit Product Screen
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String pid = ((TextView) view.findViewById(R.id.pid)).getText()
.toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
EditProductActivity.class);
// sending pid to next activity
in.putExtra(TAG_PID, pid);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}
// Response from Edit Product Activity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AllProductsActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
NewProductActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
AllProductsActivity.this, productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating listview
setListAdapter(adapter);
}
});
}
}
}
What I have to change, so I can use that as a fragment?
Edit:
i tried to change the code a little bit following some tutorials on the web...
now it works better, but there is still some problems with onPostExecute...
the doInBackground gets all parameters from mysql. i can track that with debug, but somehow after doInBackground it get's there is an error..
package com.example.androidhive;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class AllProductsActivity extends ListFragment {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://10.0.2.2/android_connect/get_all_products.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_PID = "pid";
private static final String TAG_NAME = "name";
// products JSONArray
JSONArray products = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
// Hashmap for ListView
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
return inflater.inflate(R.layout.all_products, container, false);
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
// adding HashList to ArrayList
productsList.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
getActivity().runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
getActivity(), productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.pid, R.id.name });
// updating listview
setListAdapter(adapter);
}
});
}
}
}
You must create fragment in FragmentActivity. All code you need is below
MainActivity.java
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activity);
int index=0;
MyListFragment f = MyListFragment.newInstance(index);
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.mylist, f);
ft.commit();
}//end oncreate
}//end activity
Layout fragment_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:baselineAligned="false"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/mylist"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
MyListFragment.java
public class MyListFragment extends ListFragment {
public static MyListFragment newInstance(int index) {
MyListFragment f = new MyListFragment();
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_mylist, container, false);
//read products from web and list
//productsList = new ArrayList<HashMap<String, String>>();
//new LoadProducts().execute();
return v;
}
//end oncreateview
class LoadProducts extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... args) {
return null;
}
protected void onPostExecute(String file_url) {
}
}
//end LoadProducts
}
layout_mylist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/details"
android:text="some text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white"
android:textColor="#drawable/black"
android:textStyle="bold"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

Categories

Resources