Multiple Custom ListFragment in view pager - android

I have a viewPager that include 3 different fragments with associated layouts (fragment_new_quiz, fragment_completed_quiz, fragment_created_quiz. Each one implements the onCreateView similarly like:
public class NewQuizFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_new_quiz, container, false);
mListView = (ListView) getActivity().findViewById(R.id.list);
mArrayAdapter = new QuizAdapter(mItemList, getActivity());
mArrayAdapter.setNotifyOnChange(true);
setListAdapter(mArrayAdapter);
return rootView;
}
}
The layouts should all be different so I cannot reuse them. They are defined similarly to:
<?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:background="#fa6a6a"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/createButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create" />
<TextView
android:id="#+id/intro_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Created Quiz"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="299dp" >
<ListView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView
android:id="#+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No items."
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>
</LinearLayout>
The problem I face is with this code configuration, eclipse gives me the error:
list cannot be resolved or is not a field
related to this line
mListView = (ListView) getActivity().findViewById(R.id.list);
If however I change any of the 3 listview ids to something else in any of the 3 fragments, I don't get the compile time error. However, when I run the code, I get the following error:
11-16 16:32:52.533: E/AndroidRuntime(20935):
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'.
I am kind of clueless about what to do. Is my usage of the various components not appropriate?

In your XML, change these
android:id="#+id/android:list"
android:id="#+id/android:empty"
to these:
android:id="#android:id/list"
android:id="#android:id/empty"
In your Fragments, change
mListView = (ListView) getActivity().findViewById(R.id.list);
to
mListView = (ListView) rootView.findViewById(android.R.id.list);
These are the proper ways to reference resource ids declared in the android namespace.

Related

emptyView not being replaced by listView

I have an empty view which I set via the ListView object that I have created. The issue that I'm facing is that even when the list is populated, the empty view is still shown and not the populated list view (I've tried removing the empty view and it works correctly).
Here's the code for the xml layout of the activity where I have the ListView and empty view(they're in a relative layout):
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/requests_list"
/>
<TextView
android:id="#+id/no_requests_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No current requests"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:fontFamily="sans-serif-smallcaps"
android:visibility="gone"
/>
Here's how I set the empty view:
View emptyView = findViewById(R.id.no_requests_textView);
RequestAdapter requestAdapter = new RequestAdapter(this, requestDetailsArrayList);
ListView requestsListView = (ListView) findViewById(R.id.requests_list);
requestsListView.setAdapter(requestAdapter);
requestsListView.setEmptyView(emptyView);
Does anyone know what the issue is?
Thanks in advance!
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="#+id/no_requests_textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:text="no request" >
</TextView>
TextView emptyView = findViewById(R.id.no_requests_textView);
if(requestDetailsArrayList.size()==0)
{
emptyView.setVisibility(View.VISIBLE);
ListView.setVisibility(View.GONE)
}
else
{
emptyView.setVisibility(View.GONE);
ListView.setVisibility(View.VISIBLE)
}
What you need to do is remove the emptyview from the main layout and make it in different layout and add following lines:
ViewGroup parentGroup = (ViewGroup) requestsListView.getParent();
View empty = getActivity().getLayoutInflater().inflate(R.layout.empty_view,
parentGroup,
false);
parentGroup.addView(empty);
requestsListView.setEmptyView(empty);

ListFragment with custom layout doesn't populate empty list notifier

I have created a custom layout for ListFragment, using ArrayAdapter, but when the array is empty, no empty message is displayed. I get no errors on the console. My min SDK version is 15, there should be no need to use support libraries.
headline_list.xml (i.e. my custom layout file)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#id/android:list" />
<TextView android:id="#+id/my_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
HeadlineFragment.java
public class HeadlineFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.headline_list, container, false);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<String> headlines = ...; // populate headlines list
setListAdapter(new ArrayAdapter<String>(getActivity(),
R.layout.headline_list, R.id.my_text, headlines));
}
}
You are getting suggestions here, you should do the tries.. Anyway this layout is working perfectly for me:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, from);
setListAdapter(adapter);
return rootView;
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragmet"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- Here is the view to show if the list is emtpy -->
<TextView
android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Results" />
</RelativeLayout>
I had simply forgot to set the text!
After setting it, my TextView is displayed correctly:
<TextView android:id="#id/android:empty"
android:textSize="16sp"
android:textStyle="bold"
android:text="#string/empty_text"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
with string resource in strings.xml file:
<string name="empty_text">There are no data</string>
Unfortunately, the TextView is also displayed in each row of the list, but this is another question.
It may be related to the linear layout and the fact you didn't specified weight attribute to each of the items, so one may overlay another. Check your layout params and this:
Showing empty view when ListView is empty

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I know that there has been simialr questions but I can't make it work even though I look at those. The error message is:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'
. I have tried to change the id to list. In another. This what the code looks like:
public class committeeFragment extends SherlockListFragment {
private CommitteeAdapter adapter;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CommitteeAdapter(getActivity().getApplicationContext());
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.fragment_committee, container, false);
}
public void
refreshList() {
adapter.updateDataSet();
adapter.notifyDataSetChanged();
}
}
It's using the following adapter:
public class CommitteeAdapter extends BaseAdapter {
private
ArrayList<StudentCommittee> committeeList;
private Context context;
public CommitteeAdapter(Context context) {
this.context = context;
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
public void updateDataSet() {
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
StudentCommittee committee = committeeList.get(position);
View v = vi.inflate(R.layout.list_item_committee, null);
TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);
sectionName.setText(committee.getName());
return v;
}
#Override
public int getCount() {
return committeeList.size();
}
#Override
public StudentCommittee getItem(int position) {
return committeeList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
}
Here is the xml-file that specifies the list(fragment_committee):
<?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"
android:tag="#string/tag_fragment_committee"
android:background="#color/white" >
<TextView
style="#style/AppsolutText.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Festerier" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#drawable/divider_sliding_menu_item"/>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
style="#style/AppsolutText.Normal"
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Uppdatera för att se en lista över festerier och fadderier. Kräver internetanslutning."/>
</LinearLayout>
Here is the xml for the list item:
<?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="horizontal" >
<ImageView
android:id="#+id/committee_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
<TextView
android:id="#+id/committee_namn"
style="#style/AppsolutText.ListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I hope that you can figure out what's wrong. I have another listview that has the same id (list) in another xml-file within the project. I don't know if that's a problem. Please help me solve the problem.
The problem is here :
android:id="#+id/list"
you are adding a new id for your ListView but ListFragment needs a default Android ListView Id
change your ListView Id to :
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Change your ListView in XML to have the following id:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
It's a requirement of using ListFragment/SherlockListFragment
http://developer.android.com/reference/android/app/ListFragment.html
ListFragment has a default layout that consists of a single list view. However, if you desire, you can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle). To do this, your view hierarchy must contain a ListView object with the id "#android:id/list" (or list if it's in code)
You can try to clean your project. If any xml releted error have , you can find it. Then you can change your list id . Find the list id are exist into your gen folder R.java class.
I decided to stop using actionbarsherlock and use the support libraries instead to get action bar in Android 2.1 and above. After doing this, i got the "java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'". What i did to remedy this problem was
to read this http://developer.android.com/reference/android/app/ListFragment.html#q=fragment
then change my fragment layout file from
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context=".ItemDetailFragment" />
to
<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"
android:paddingLeft="8dp"
android:paddingRight="8dp"
tools:context=".ItemDetailFragment">
<ListView android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:text="No data"/>
... and voila, the RunTimeException with missing android.R.id.list was gone! Of course, i need to edit my new layout and fix it properly, but the key issue here was that i had overridden the fragment layout in its onCreateView method. ActionBarSherlock DID NOT have a problem with this, but with the Android support library, if u do this, you MUST have a ListView in your XML Layout, with the android:id="#id/android:list" as stated in the info linked to above.
Hope this helps (coming from a total newb in Android app dev)!

ClassCastException when calling ListView.addHeaderView()?

I have a fairly complex layout (containing RelativeLayouts, TextViews and ImageViews) that I want to place above a listview. This view should scroll with the listview.
I tried adding the layout as a header to the listview using this code:
View v = inflater.inflate(R.layout.list_view, container, false);
View header = inflater.inflate(R.layout.header_layout, container, false);
// populate views in the header
mList = (ListView)v.findViewById(R.id.list);
mList.addHeaderView(header);
mAdapter = new ReviewsAdapter(getActivity());
mList.setAdapter(mAdapter); <-- error occurs here
ReviewsAdapter is a custom adapter I've written which extends BaseAdapter.
Upon executing the code, I get this error:
11-25 17:19:14.802: E/AndroidRuntime(1215): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.clearRecycledState(ListView.java:513)
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.resetList(ListView.java:499)
11-25 17:19:14.802: E/AndroidRuntime(1215): at android.widget.ListView.setAdapter(ListView.java:442)
11-25 17:19:14.802: E/AndroidRuntime(1215): at com.coppi.storefront.product.ProductReviewsFragment.onCreateView(ProductReviewsFragment.java:104)
If I comment out the mList.addHeaderView(header) line I do not get the error. I can also display the header layout without the listview with no problems.
I'm assuming this has something to do with the contents of the header layout but I'm not sure exactly what would be causing it.
Here is the header xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/header_section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_sides"
android:background="#color/pdp_availability_section_background" >
<TextView
android:id="#+id/header_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_sides"
android:paddingBottom="#dimen/margin_sides"
android:text="#string/ratings_reviews"
android:textColor="#000"
android:textSize="18dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/body_section"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/header_section" >
<TextView
android:id="#+id/product_title"
style="#style/ProductTitleFont"
android:layout_marginBottom="#dimen/product_title_bottom_margin"
android:layout_marginLeft="#dimen/margin_sides"
android:layout_marginRight="#dimen/margin_sides" />
<RelativeLayout
android:id="#+id/attributes_section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_title"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/margin_sides" >
<LinearLayout
android:id="#+id/overall_section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom" >
<TextView
android:id="#+id/overall_label"
style="#style/ProductTitleFont"
android:layout_width="wrap_content"
android:text="#string/overall_rating" />
<ImageView
android:id="#+id/overall_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/icon_rating_empty" />
<ImageView
android:id="#+id/overall_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_rating_empty" />
<ImageView
android:id="#+id/overall_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_rating_empty" />
<ImageView
android:id="#+id/overall_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_rating_empty" />
<ImageView
android:id="#+id/overall_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_rating_empty" />
<TextView
android:id="#+id/overall_score"
style="#style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:text="4.6" />
</LinearLayout>
<Button
android:id="#+id/rate_review_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/overall_section"
android:layout_marginBottom="#dimen/margin_sides"
android:layout_marginTop="#dimen/margin_sides"
android:text="#string/rate_review_button_text" />
</RelativeLayout>
<View
android:id="#+id/attributes_divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#id/attributes_section"
android:layout_marginBottom="#dimen/margin_sides"
android:layout_marginTop="#dimen/margin_sides"
android:background="#color/pdp_section_divider" />
<TextView
android:id="#+id/review_count"
style="#style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_below="#id/attributes_divider"
android:layout_marginLeft="#dimen/margin_sides"
android:text="0 " />
<TextView
style="#style/ProductTitleFont"
android:layout_width="wrap_content"
android:layout_alignBaseline="#id/review_count"
android:layout_marginRight="#dimen/margin_sides"
android:layout_toRightOf="#id/review_count"
android:text="#string/customer_reviews" />
<View
android:id="#+id/review_count_divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#id/review_count"
android:layout_marginBottom="#dimen/margin_sides"
android:layout_marginTop="#dimen/margin_sides"
android:background="#color/pdp_section_divider" />
</RelativeLayout>
</RelativeLayout>
Update: I tried reducing the header .xml file to just a single TextView and the problem continues. So I don't believe the problem is being cause by something in the xml.
FrameLayout and AbsListView convert their children layout params to FrameLayout.LayoutParams and AbsListView.LayoutParams. This is where the casting fails.
View header = View.inflate(this, R.layout.header_layout, null);
should fix it.
Edit:
As mentioned in the comments, changing the ViewGroup Parameter of the inflate call also makes it work:
header = inflater.inflate(R.layout.header_layout, null, false);
Although Souvlaki's method will fix the issue and allow you to continue working. It is always best to give the view being inflated a reference to the container it will be in. This allows for Android to correctly inflate it for the right context.
What you should do is find the ListView and then pass that to the inflate.
ListView listView = (ListView) layout.findViewById(R.id.listview);
View header = inflater.inflate(this, R.layout.header_layout, listView, false);
I see same situation.
in my case, it's a trouble that call timing for ListView.addHeaderView().
Before: (Error)
ListView.addHeaderView() is called in Fragment.onCreateView() method.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_main, container, false);
mListView = (ListView) layout.findViewById(R.id.listview);
mListView.addHeaderView(inflater.inflate(R.layout.list_header_book, listview, false));
return layout;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new BookAdapter(getActivity(), mBookList);
mListView.setOnItemClickListener(mBookItemClickListener);
mListView.setAdapter(mAdapter);
}
After:(OK)
ListView.addHeaderView() is called in Fragment.onActivityCreated() method.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new BookAdapter(getActivity(), mBookList);
mListView = (ListView) getView().findViewById(R.id.listview);
mListView.setOnItemClickListener(mBookItemClickListener);
mListView.addHeaderView(LayoutInflater.from(getActivity()).inflate(R.layout.list_header_book, null));
mListView.setAdapter(mAdapter);
}
From drspaceboo's post above, this worked for me:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
mListLayoutView = inflater.inflate(getLayoutId(), container, false);
int headerLayoutId = R.layout.list_header_layout;
mListHeaderView = inflater.inflate(headerLayoutId, mResourcesListView, false);
// ...
mResourcesListView.addHeaderView(mListHeaderView, null, false);
Where getLayoutId() returns the main layout that contains the ListView xml

Implementing a listview inside a sliding drawer with a listview already present

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);

Categories

Resources