When i click an already existing element in my ListView, im changing its color, but i also want to place it at the bottom of the ListView
Is there a way to place a given View from a ListView to the bottom of the ListView?
Are you talking about footer view this how it is implemented.
Your footer xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center">
<TextView
android:text="#string/footer_text_1"
android:id="#+id/footer_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textStyle="bold"
android:layout_marginRight="5dip" />
</LinearLayout>
</LinearLayout>
Your activity class
public class MyListActivty extends ListActivity {
private Context context = null;
private ListView list = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
list = (ListView)findViewById(android.R.id.list);
//code to set adapter to populate list
View footerView = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
list.addFooterView(footerView);
}
Related
I am having problems with ListView on android. I have an Activity with an EditText view and a button. The idea is user should enter some info in the EditText field, touch the Search button which retrieves a list from a web service that it is displayed in the same activity below the EditText and the Button. Everything fine, I got the data from Internet but items weren't displaying. I was using the notifyDataSetChanged(). After a couple of hours with no success, I decided trying to put some items manually and it turns out that again nothing was displayed, hence I think I am doing something wrong when I am trying to set the listview and the adapter. So here is the code..
the xml of the activity activity_search.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<EditText
android:id="#+id/edit_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:inputType="text"
android:hint="Enter info"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/ic_menu_search"
android:contentDescription="Search"
android:ems="10" />
</LinearLayout>
<ListView
android:id="#+id/listview_items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
The XML of the item row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="5dp">
<TextView
android:id="#+id/row_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Common_TextContent"
android:textAppearance="#android:style/TextAppearance.Holo.Medium" />
<TextView
android:id="#+id/row_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/Common_TextContent"
android:textAppearance="#android:style/TextAppearance.Holo.Small" /></LinearLayout>
the custom Adapter:
public class ItemsListAdapter extends ArrayAdapter<ItemsList> {
private int[] colors = new int[] { 0x30ffffff, 0x30808080 };
public AssetListAdapter(Context context,
List<ItemsList> itemsList) {
super(context, 0, itemsList);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null);
}
convertView.setBackgroundColor(colors[position % colors.length]);
TextView code = (TextView) convertView.findViewById(R.id.row_code);
code.setText(getItem(position).getCode());
TextView name = (TextView) convertView.findViewById(R.id.row_name);
name.setText(getItem(position).getName());
return convertView;
}
and the onCreate method on the Activity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
_listView = (ListView) findViewById(R.id.listview_items);
_listItems = new ArrayList<ItemsList>();
_listItems.add(new ItemsList ("cosa1", "cosa1", "cosa1", "cosa1"));
_listItems.add(new ItemsList ("cosa2", "cosa2", "cosa2", "cosa2"));
_listItems.add(new ItemsList ("cosa3", "cosa3", "cosa3", "cosa3"));
_adapter = new ItemsListAdapter(this, _listItems);
_listView.setAdapter(_adapter);
}
The ItemsList is just an Object with 4 strings with all the getters implemented.
When I debug in the getView method of the Adapter, the view (convertView) is created and it has the right information. It is just that is not showing those in the screen. What am I doing wrong?
Thanks...
Your second LinearLayout has a height of match_parent. Try wrap_content instead.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
My app generates 2 different lists, one uses the default ListView style as the ListView rows contain no TextView inside of them. The other list uses a custom CursorAdapter and has a TextView inside each row. All I want to do is make it so that the margins and text size are exactly the same for both lists.
My first list is using a standard ListView with no TextView inside each row, here is what it looks like:
Here is the code to generate it:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.records);
DatabaseHandler db = new DatabaseHandler(this);
ArrayList<String> records = db.getRecords(this);
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, records));
}
Here is the xml file for it:
<?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="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
My second list is using a ListView with a TextView inside each row that is generated via a custom `CursorAdapter, here is what it looks like:
Here is the code to generate it:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.achievements);
DatabaseHandler db = new DatabaseHandler(this);
Cursor cursor = db.getAchievements(this);
AchievementAdapter cursorAdapter = new AchievementAdapter(this, cursor);
this.setListAdapter(cursorAdapter);
}
private class AchievementAdapter extends CursorAdapter {
public AchievementAdapter(Context context, Cursor c) {
super(context, c);
}
#Override
public void bindView(View v, Context context, Cursor cursor) {
TextView tv = (TextView) v.findViewById(R.id.achView1);
if(cursor.getString(cursor.getColumnIndex("completed")).equals("yes")) {
tv.setText(cursor.getString(cursor.getColumnIndex("name"))+" (completed)");
tv.setTextColor(Color.GREEN);
}
else {
tv.setText(cursor.getString(cursor.getColumnIndex("name")));
}
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.achievements_item, parent, false);
return v;
}
}
Here is the achievements xml file for it:
<?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="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""/>
</LinearLayout>
Here is the achievements_item xml for it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/achView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="" />
</LinearLayout>
Basically I just want these 2 lists to look exactly the same. Is there a way to do it so that the TextView inherits the default ListView row style? Or am I going to have to play with the margins and everything myself?
Just copy the attributes of the TextView from the default ListView layout android.R.layout.simple_list_item_1 and use them on your own row layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/achView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight" />
</LinearLayout>
Also, if all you want for the customized ListView row layout is a TextView, you could remove the parent LinearLayout so you don't have an extra View in the layout
In achievements_item.xml add some padding to the top and bottom of the TextView
<TextView
android:id="#+id/achView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="" />
hi all i m making a sample app. for update List.
i have a list class and its xml is like.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/ListView01" android:layout_height="wrap_content"
android:layout_width="fill_parent"></ListView>
<TextView android:id="#+id/more"
android:layout_height="wrap_content"
android:text="Click to view more..."
android:textStyle="normal|bold" android:textColor="#FF8000" android:textSize="10dip"
android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent">
</TextView>
</LinearLayout>
now i have set TouchListener of text View and added the following code in it
#Override
public boolean onTouch(View v, MotionEvent event) {
switch(v.getId())
{
case R.id.more:
//update List Method Call..
more.setText("Click to view More..");
adapter.notifyDataSetChanged();
}
// TODO Auto-generated method stub
return false;
}
You see on the 3rd line of switch statement i have added
more.setText("Click to view More..");
line but when my list is updated . The text View is no longer shows in the bottom .
Please Guide my why this is happening to me and whats the solution??
you can use list footer in that case.
add this code in ur java file. and add footer dynamically in your list.
TextView more = new TextView(this);
more.setText("Click to view more...");
more.setClickable(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, Height);
more.setLayoutParams(params);
more.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//update List Method Call..
more.setText("Click to view More..");
adapter.notifyDataSetChanged();
}
});
ListView listView = (ListView) findViewById(R.id.ListView01);
listView.addFooterView(more);
this can help you.
try this ...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/ListView01" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_height="fill_parent" android:layout_above="#+id/more"></ListView>
<TextView android:id="#+id/more"
android:layout_height="wrap_content"
android:text="Click to view more..."
android:textStyle="normal|bold" android:textColor="#FF8000" android:textSize="10dip"
android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent" android:layout_alignParentBottom="true">
</TextView>
</RelativeLayout>
try android:layout_height="fill_parent" android:layout_above="#+id/more" in the ListView. Now even if ur ListView grows it wont hide the TextView.
UPDATE
<RelativeLayout android:id="#+id/relativeList"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/LinearBottom3">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/chathlist"
/>
</RelativeLayout>
<RelativeLayout android:id="#+id/LinearBottom3"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content"><!--Make it as center-->
<TextView android:id="#+id/more" android:layout_height="wrap_content"
android:text="Click to view more..." android:textStyle="normal|bold" android:textSize="10dip"
android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"/>
</ReletiveLayout>
try this..
footer.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:textSize="30dip" android:gravity="center_horizontal"
android:text="Click to view More.." android:layout_width="fill_parent"
android:id="#+id/more"></TextView>
</LinearLayout>
in class file
LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout footer = (LinearLayout)inflater.inflate(
R.layout.footer, null);
TextView more= (TextView)footer.findViewById(R.id.more);
more.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
//List Update Code
}
});
use the following code..
footer_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center">
<TextView
android:text="footer_text_1"
android:id="#+id/footer_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textStyle="bold"
android:layout_marginRight="5dip">
</TextView>
</LinearLayout>
</LinearLayout>
and use the following in code:
public class listactivty extends ListActivity{
private Context context = null;
private ListView list = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
list = (ListView)findViewById(android.R.id.list);
//code to set adapter to populate list
View footerView =
((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
list.addFooterView(footerView);
}
use seperate XML file for ListView..
Thanks
Shahjahan Ahmad
How to use a layout as empty view for a listview when the adapter has zero elements?
setEmptyView is not working with this code :
public class ZeroItemListActivity extends Activity {
private ArrayList<String> listItems=new ArrayList<String>();
private ListView mMyListView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMyListView=(ListView) findViewById(R.id.MyListView);
mMyListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listItems));
LayoutInflater inflator=getLayoutInflater();
View emptyView=inflator.inflate(R.layout.empty_list_item, null);
//Empty view is set here
mMyListView.setEmptyView(emptyView);
}
public void addItem(View v){
listItems.add("list Item");
mMyListView.invalidate();
}
}
Layouts used : empty_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="#+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Empty List,Click to add items"></Button>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/hello" />
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/MyListView"></ListView>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/AddItemsButton"
android:text="Add Items" android:onClick="addItem"></Button>
</LinearLayout>
The easiest way to get this done is to put the empty view in the main.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/MyListView">
</ListView>
<!-- empty view -->
<LinearLayout android:id="#+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Empty List,Click to add items">
</Button>
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AddItemsButton"
android:text="Add Items"
android:onClick="addItem"></Button>
</LinearLayout>
Then, in your code, set your empty view like this:
mMyListView.setEmptyView(findViewById(R.id.emptyView));
The reason your code isn't working is that the ListView and Empty view need to be in the same view heirarchy. And your call to inflate pass null as the parent so they are in different heirarchies.
The Android Dev tutorial for List Activity covers this topic:
http://developer.android.com/reference/android/app/ListActivity.html
Basically have your class extend ListActivity. Set your list id to #id/android:listand the "empty view" id to #id/android:emptyin the same XML layout.
Hope this helps :)
When, inflating the view, you have to set the view parent to be part of the Layout hierarchy rather than pass null in some cases.
Replace
View emptyView = inflator.inflate(R.layout.empty_list_item, null);
with
View emptyView = inflator.inflate(R.layout.empty_list_item, (ViewGroup) mMyListView.getParent());
then you set the empty view as you did before with.
mMyListView.setEmptyView(findViewById(R.id.emptyView));
I have an app whose main class extends ListActivity:
public class GUIPrototype extends ListActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Cursor c = managedQuery(People.CONTENT_URI, null, null, null, null);
String[] from = new String[] {People.NAME};
int[] to = new int[] { R.id.row_entry };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.drawer,c,from,to);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
}
}
I have a sliding drawer included in my XML, and I'm trying to get a separate listview to appear in the sliding drawer. I'm trying to populate the second listview using an inflater:
View inflatedView = View.inflate(this, R.layout.main, null);
ListView namesLV = (ListView) inflatedView.findViewById(R.id.content);
String[] names2 = new String[] { "CS 345", "New Tag", "Untagged" };
ArrayAdapter<String> bb = new ArrayAdapter<String>(this, R.layout.main, R.id.row_entry, names2);
namesLV.setAdapter(bb);
This compiles, and runs, but the slidingdrawer is completely blank. My XML follows:
<SlidingDrawer
android:id="#+id/drawer"
android:handle="#+id/handle"
android:content="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<ImageView
android:id="#id/handle"
android:layout_width="48px"
android:layout_height="48px" android:background="#drawable/icon"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#id/content"/>
</SlidingDrawer>
I feel like I'm missing a vital step. I haven't found any resources on my problem by Googling, so any help would be greatly appreciated.
Edit: This was for a problem a long time ago, and the solution I found was to just redesign my layout. I am unable to accept an answer as I don't have the means to test them.
I Suppose I might have found the solution.
All these above solutions did not worked for me.
But then, what I did was add onClickListener to actual view which I return from adapter and BAM it started working for me.
Here is the sample code:
May layout XML (Not complete one....)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id = "#+id/scrolling"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:paddingBottom="30dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/listingIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
............
</ScrollView>
<SlidingDrawer
android:id="#+id/slidingDrawerShowMore"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:topOffset="132dip"
android:handle="#+id/handle"
android:content="#+id/content">
<LinearLayout
android:id="#+id/handle"
android:padding = "5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/black">
<TextView
android:id="#+id/title"
android:layout_alignParentRight="true"
android:textSize="14dp"
android:layout_below="#id/rate"
android:singleLine="true"
android:textColor="#3F48CC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/show_more"/>
</LinearLayout>
<LinearLayout
android:id="#id/content"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:gravity="center"
android:background="#android:color/black">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:background="#drawable/dark_header">
<TextView
android:id="#+id/otherTitle"
android:layout_alignParentRight="true"
android:layout_below="#id/rate"
android:singleLine="true"
android:textSize="21px"
android:paddingLeft="10px"
android:textColor="#EBEBEB"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="0.6"
android:text="#string/someString"/>
<ProgressBar
android:id="#+id/pbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Now to handle click events all I had to do was to add onClickListener in my adapter
public View getView(int position, View convertView, ViewGroup parent) {
convertView.setOnClickListener(this);
}
That's it. Problem is I could not get my onItemClickListener working for this ListView. But right now on click listener works for me. One day I would love to find out reason behind this.
It looks like the problem could be that you are inflating a new instance of a ListView rather than using the one in your view.
Try getting the ListView with ListView listView = (ListView) findViewById(R.id.content);
Then apply your adapter to it.
Have you tried
View inflatedView = View.inflate(this, R.layout.main, null);
SlidingDrawer sliding=(SlidingDrawer) inflatedView.findViewById(R.id.drawer);
ListView namesLV = (ListView) sliding.findViewById(R.id.content);