Listview will not populate - java

Alright I'm stuck on populating a ListView in Android. This must be a tiring question for you guys but I can't find the problem. Basically it will produce placements in the ListView to hold texts, but it wont produce text. I checked my database class and it seems to be storing the data correctly, and I checked the syntax, but I cant find the problem.
Main activity that holds the list view
public class MainScreen extends ListActivity {
private TextView roommateId;
dbHelper db = new dbHelper(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
Log.i("Created", "main created");
ArrayList<HashMap<String, String>> roommates = db.getAllRoommates();
if(roommates.size()!=0){
ListView listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
roommateId = (TextView) view.findViewById(R.id.roommateId);
String roommateIdValue = roommateId.getText().toString();
Intent intent = new Intent(getApplication(), RoommateView.class);
intent.putExtra("roommateId", roommateIdValue);
startActivity(intent);
}
});
ListAdapter adapter = new SimpleAdapter(MainScreen.this, roommates, R.layout.contact_entry,
new String[] {"roommateId", "firstName", "lastName"},
new int[]{R.id.roommateId, R.id.lastName, R.id.firstName});
setListAdapter(adapter);
}
}
Database code that returns the array list
public ArrayList<HashMap<String,String>> getAllRoommates(){
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
String query = "SELECT * FROM " + DB_TABLE;
SQLiteDatabase data = this.getWritableDatabase();
Cursor cursor = data.rawQuery(query, null);
if(cursor.moveToFirst()){
do{
HashMap<String,String> roommateMap = new HashMap<String, String>();
roommateMap.put(ID, cursor.getString(0));
Log.d("Roommate ID", cursor.getString(0));
roommateMap.put(FIRST_NAME, cursor.getString(1));
Log.d("First Name", cursor.getString(1));
roommateMap.put(LAST_NAME, cursor.getString(2));
list.add(roommateMap);
}while(cursor.moveToNext());
}
return list;
}
contact entry xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/last_name"
android:id="#+id/lastName"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/first_name"
android:id="#+id/firstName"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/id"
android:id="#+id/roommateId"/>
</TableRow>
Main screen xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000" >
<TextView
android:id="#+id/contactsTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:layout_weight="1"/>
<Button
android:id="#+id/button1"
android:background="#444444"
android:onClick="showAddRoommate"
android:text="#string/add_roommate"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</TableRow>
</TableLayout>

Alright, I think I found the problem, it was that the String array in the simple adapter wasn't corresponding to the hash map key values, so when it was looking for key values that were not in the Hash Map. Change that and it populated. Putting the answer down incase anyone in the future sees this post.

Related

TextView in listViews added inside a Fragment displaying but empty (no text)

I want to display a list of items containing 2 textview in one of my fragment. Something really simple since I'm learning how to use listviews.
Here is my code:
public class CommandeFragment extends Fragment{
private BarMenu myMenu;
View myView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.commande_layout,container, false);
myMenu = (BarMenu) getArguments().getSerializable(MENU_KEY);
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i = 0; i < myMenu.drinks.size(); i++){
HashMap<String,String> hm = new HashMap<String, String>();
hm.put("Name",myMenu.drinks.get(i).drinkName);
hm.put("Price",myMenu.drinks.get(i).drinkPrice.toString());
aList.add(hm);
}
String[] from = {"drinkName","drinkPrice"};
int[] to = {R.id.textView3,R.id.textView4};
SimpleAdapter adapter = new SimpleAdapter(myView.getContext(), aList, R.layout.listview_commande_layout, from, to);
ListView listView = (ListView) myView.findViewById(R.id.listView);
listView.setAdapter(adapter);
return myView;
}
}
When I run this, I got a list of textviews placed correctly but the problem is that the text inside is empty. I've try multiple advice about the xml files online but I'm pretty sure it's fine.
Here it is in case:
listview_commande_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_weight="1" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
commande_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:text="Bar Menu Layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:id="#+id/textView2" />
</RelativeLayout>
The column names you pass to your adapter don't match the column names in your HashMap ("Name" vs. "drinkName"). If you update these to match, it should work.
for(int i = 0; i < myMenu.drinks.size(); i++){
HashMap<String,String> hm = new HashMap<String, String>();
hm.put("Name",myMenu.drinks.get(i).drinkName);
hm.put("Price",myMenu.drinks.get(i).drinkPrice.toString());
aList.add(hm);
}
String[] from = {"Name","Price"}; //changed from {"drinkName","drinkPrice"}

I'm trying to implement Listview in an normal activity in Android. I managed to show items to Listview but I'm not being able to detect clicks

public class homescreenjava extends AppCompatActivity {
public void addNewFields(View view) {
Intent callnew =new Intent(this,AddNewField.class);
startActivity(callnew);
}
public void showUserInfo(View view){
Intent callnew =new Intent(this,showuserinfo.class);
startActivity(callnew);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homescreen);
ListView m_listview = (ListView) findViewById(R.id.list_view);
SQLiteOpenHelper AgroDatabase = new AgroDatabase(this);
SQLiteDatabase db = AgroDatabase.getReadableDatabase();
Cursor cursor=db.query("fieldinfo",new String[]{"_id", "FieldName","Area"},null,null,null,null,null);
CursorAdapter listAdapter= new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
new String[]{"FieldName"},
new int[]{android.R.id.text1},0);
m_listview.setAdapter(listAdapter);
}
#Override
protected void onDestroy() {
super.onDestroy();
cursor.close();
db.close();
}
}
Iam also not being able to close cursor and database here on the same class. cursor and db cant be resolved here is the error message
#Override
protected void onDestroy() {
super.onDestroy();
cursor.close();
db.close();
}
I read that onListItemClick can be implemented if my class extends listActivity
can I implement this method in my case or is there any other solution
public void onListItemClick(ListView listview,
View itemView,
int position,
long id){
Intent intent=new Intent(homescreenjava.this,SecondHome.class);
startActivity(intent);
}
just for reference i am putting my xml code for this activity . listview is at the last of xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_homescreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingStart="#dimen/activity_horizontal_margin"
android:paddingEnd="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.sagar.ahs.homescreenjava"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="120dp"
android:layout_height="77dp"
app:srcCompat="#drawable/leaf"
android:id="#+id/imageView2"
android:layout_gravity="end"
android:background="#color/colorAccent"
/>
<TextView
android:text="#string/app_name"
android:layout_width="match_parent"
android:layout_height="77dp"
android:id="#+id/textView2"
android:textSize="30sp"
android:textScaleX="2"
android:gravity="start|center"
android:elevation="1dp"
android:textColor="#aaaf"
android:textStyle="normal|bold"
android:background="#color/colorAccent"
/>
</LinearLayout>
<TextView
android:text="#string/main_page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center"
android:id="#+id/textView5"
android:layout_weight="7.88"
android:textStyle="normal"
android:textSize="20sp"
android:background="#color/colorPrimary"
android:textColor="#ffff"
android:paddingStart="10dp"
android:paddingEnd="2dp"
android:paddingTop="10dp"
android:paddingBottom="8dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/plus"
android:id="#+id/imageButton8"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:tint="#ffff"
android:onClick="addNewFields"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/boss"
android:id="#+id/imageView"
android:tint="#ffff"
android:background="#color/colorPrimary"
android:layout_weight="1"
android:onClick="showUserInfo"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="#string/button_info_field"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:id="#+id/textView7"
android:textColor="#ffff"
android:textSize="23sp"
android:background="#color/colorPrimary"
android:gravity="fill"
android:layout_weight="0.76"/>
<TextView
android:text="#string/button_info_UI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_weight="1"
android:textColor="#ffff"
android:textSize="23sp"
android:background="#color/colorPrimary"
android:gravity="fill"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:divider="#color/colorPrimary"
android:dividerHeight="3dp"
android:id="#+id/list_view"
/>
</LinearLayout>
To close the database and cursor, first you have to make cursor and db global variable, like this:
private SQLiteDatabase db;
private Cursor cursor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homescreen);
ListView m_listview = (ListView) findViewById(R.id.list_view);
SQLiteOpenHelper AgroDatabase = new AgroDatabase(this);
db = AgroDatabase.getReadableDatabase();
cursor = db.query("fieldinfo", new String[]{"_id", "FieldName", "Area"}, null, null, null, null, null);
Now you can close in ondestroy function.
To handle onclick of listview items, follow the below code inside oncreate:
m_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.v("TAG","listview item clicked");
}
});

Advice on android setlistadapter and combining two .xml layout

I am using two list adapter as shown on code below. resultList and resultList2 are initialized with new ArrayList <HashMap<String,String>>();
ListAdapter adapter, adapter2;
adapter =new SimpleAdapter(
getActivity(), resultList,
R.layout.list_item1, new String[]{TAG_ID, TAG_FRUIT, TAG_SPECIES},
new int[]{R.id.Id,R.id.fruit,R.id.species});
adapter2=new SimpleAdapter(
getActivity(), resultList2,
R.layout.list_item_append, new String[]{ TAG_NAME, TAG_ADDRESS, TAG_EMAIL},
new int[]{ R.id.name, R.id.address, R.id.email});
setListAdapter(adapter);
setListAdapter(adapter2); //this line has overriden setListAdapter(adapter)
I have two layouts named list_item1.xml and list_item2.xml.
//list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/Id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold"
android:descendantFocusability="blocksDescendants"
android:visibility="gone"/><!--android:visibility="gone" -->
<TextView
android:id="#+id/fruit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/species"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold" />
</LinearLayout>
second layout: list_item2.xml
list_item.xml
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold" />
I have tried to use <include> and <merge> in my new layout but it is not the result I wanted. The result shows all the elements in adapter2. But there are empty list element before each of the adapter2 elements.
My expected result are:
adapter....
adapter....
adapter...
adapter2...
adapter2...
adapter2...
How can I achieve this? I think that setListAdapter is the cause of the problem.
The reason i used two listadapter is because i am trying two fetch two set of data from my database. The data is fetch from the table named tblfruit and tblperson.
$response["results"] = array();
$response["results2"] = array();
// temp user array
$results = array();
$results2=array();
while ($row = mysql_fetch_array($result)){
$results["id"] = $row["id"];
$results["fruit"] = $row["fruit"];
$results["species"] = $row["species"];
array_push($response["results"], $results);
}
while ($row = mysql_fetch_array($result2)){
$results2["name"] = $row["name"];
$results2["address"] = $row["address"];
$results2["email"] = $row["email"];
array_push($response["results2"], $results2);
}
Extend ListAdapter and inflate each row with your desired layout within the Adapter's View.getView() method. This method is called once for each row in the ListView (or record inside the adapter, if you want to be specific). It is used to set up (or, well, inflate) the view for each record, and doing things such as setting the value of TextView's, ImageView's, hiding unnecessary components for each row, etc. I haven't tried this with two differente layout resources myself, but I suppose it can be done with this approach.
public class CustomListAdapter extends ArrayAdapter<CustomObject> {
private Context context;
private int layoutResourceId_1;
private int layoutResourceId_2
private List<CustomObject> list;
public CustomListAdapter(Context context, int layoutResourceId_1, int layoutResourceId_2, List<CustomObject> list) {
super(context, layoutResourceId_1, list);
this.context = context;
this.layoutResourceId_1 = layoutResourceId_1;
this.layoutResourceId_2 = layoutResourceId_2;
this.list = list;
}
...
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater layoutInflater = ((Activity) context).getLayoutInflater();
if(condition_layout_1()) {
row = layoutInflater.inflate(layoutResourceId_1, parent, false);
// Use a holder to prepare item
...
} else {
row = layoutInflater.inflate(layoutResourceId_2, parent, false);
// Use a holder to prepare item
...
}
return row;
}
...
}
You don't need to merge list_item1 and resultList2 layouts for whatever you are trying to achieve.Instead of extending ListActivity or ListFragment, use ordinary activity and setContentView with a layout that has two listviews in its xml like below
<?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:gravity="center"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
and then in your java file
ListView listview1 = (ListView) findViewById(R.id.listView1);
ListView listview2 = (ListView) findViewById(R.id.listView2);
listview1.setAdapter(adapter);
listview2.setAdapter(adapter2);
I am not sure if this meets your requirement.Sorry if it doesn't.I hope it helps.

change image in dynamic list view

How can i change image in list view at rum time.
I want to change android:layout_toRightOf="#+id/imageView" according to the gender .
here xml
<ImageView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView"
android:text="20px"
android:textColor="#dc6800"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="21dp"
android:background="#drawable/people" />
<TextView
android:id="#+id/empid"
android:layout_width="fill_parent"
android:layout_height="1px"
android:paddingBottom="1px"
android:visibility="invisible">
</TextView>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView"
android:text="20px"
android:textColor="#dc6800"/>
</RelativeLayout>
</LinearLayout>
java code :
for (Element group : allGroups) {
String empID = XMLUtil.getNodeValue(group, EMPID );
String empName = XMLUtil.getNodeValue(group, NAME );
String gender = XMLUtil.getNodeValue(group, GENDER );
gropusMap.put(empID , group);
HashMap<String, String> map = new HashMap<String, String>();
map.put(NAME , empName);
map.put(EMPID , empID);
if(gender.equalsIgnoreCase("female")){
map.put(PHOTO , "female");
}else {
map.put(PHOTO , "male");
}
menuItems.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, menuItems , R.layout.list_item, new String[] { NAME, EMPID,PHOTO }, new int[] { R.id.name, R.id.empid ,R.id.imageView });
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {.
.
..
.
.

Android Have a Table and buttons on the same layout xml

I've got a page where I want to put a table in the middle and have buttons above and below. I've got the following XML for my layout. But even I can work out it won't work!
Edit: I've updated my XML to show what I want to achive. The tables inside, however it wont let me access by ListView listView = (ListView) findViewById(R.id.lvLocation);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Add Item" />
<ListView
android:id="#+id/lvLocation"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btnBack"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnAdd"
android:drawSelectorOnTop="false" >
</ListView>
<Button
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Back" />
</RelativeLayout>
My code: (with the Db call and array setup taken out)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_list_view);
ListView listView = (ListView) findViewById(R.id.lvLocation);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_2, android.R.id.text1, mArrayList);
int[] colors = {0, 0xFFFF0000, 0};
listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
listView.setDividerHeight(1);
listView.setAdapter(adapter);
}
}
Heres what i'm trying to achieve. Not the colours, just the concept:
I think this will help
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Add Item" />
<TableLayout
android:id="#+id/lvLocation"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btnBack"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnAdd" >
</TableLayout>
<Button
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Back" />
</RelativeLayout>
Instead of :
ListView listView = (ListView) findViewById (R.id.lvlocation);
Just use:
ListView listView = getListView();

Categories