NullPointerException when trying to add a Navigation Drawer (Android) - java

I'm a bit stuck. I have been followng some tutorials and ended up making a DrawerLayout like below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ListView
android:id="#+id/list"
android:entries="#array/menuitems"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left">
</ListView>
</android.support.v4.DrawerLayout>
I want this menu to slide in whenever the hamburger icon in my toolbar gets pressed, so I set an onClickListener in my Activity:
hamburgerIcon = (ImageView) findViewById(R.id.hamburger);
hamburgerIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String[] osArray = { "Bla", "Bla", "alB", "alB", "BLA" };
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList = (ListView) findViewById(R.id.list);
mDrawerList.setAdapter(mAdapter);
}
};
I get a NullPointer when I try to initialise the ListView (mDrawerList) - and I'm certain that's because the Activity that I'm using uses a different layout to the navigation_drawer.xml, so it is unable to find the ListView in the xml. My question is, how can I use the navigation drawer layout using my main (different) layout?
Any tips are welcome, thanks.
EDIT:
I used this tag to include the DrawerLayout in the main layout
<include layout="#layout/navigation_drawer"
android:id="#+id/navdraw"/>
However, now I'm getting a RuntimeException when opening the main layout "Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.DrawerLayout" - then it complains about the setContentView(..) line in the main activity.
I have tried adding the dependency in the gradle script
compile 'com.android.support:support-v4:20.0.0'
But it's underlined in red and says "The support library should not use a lower version (20) than the targetSdkVersion (22)".
Any ideas?

hamburgerIcon = (ImageView) findViewById(R.id.hamburger);
mDrawerList = (ListView) findViewById(R.id.list);
hamburgerIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String[] osArray = { "Bla", "Bla", "alB", "alB", "BLA" };
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
}
};
try again

It looks like the navigation_drawer.xml is not the main layout?
You can use the include tag and set the id. Then try findViewById(include_id).findViewById(R.id.list).

Related

Starting new activity from fragment starts a blank activity

I'm trying to make a basic Tourist app for my hometown. I have an onItemClickListener set on a listView. My goal is that when a list item is clicked, I want to open a new activity to show the user more information about the selected item(address, phone number, GPS location, etc). I set all the textviews in the fragment before I send the intent, so, when I setContentView, it should be displayed with all the accurate information already populated.
The problem is, when the list view is clicked, the activity starts a blank activity. There is no error message and the logCat shows that the textviews were updated correctly but they just aren't displaying correctly with the layout.
I've been working on this for days and would appreciate any help that anyone can give. Thanks in advance. Code is below.
**This is the fragment that holds the arrayList with the information to be displayed.
public class FoodFragment extends Fragment {
public FoodFragment() {
// Required empty public constructor
}
public TourSite currentSite;
#Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.sites_listview, container, false);
// Create an ArrayList of TourSite objects for main tab lists
final ArrayList<TourSite> tourSites = new ArrayList<TourSite>();
tourSites.add(new TourSite(R.string.ginasAddress, R.string.ginasNumber, R.string.ginasGPS,
R.string.ginasWeblink, R.drawable.pizza_100, R.string.ginasName));
tourSites.add(new TourSite(R.string.ninosAddress, R.string.ninosnumber, R.string.ninosGPS,
R.string.ninosWeblink, R.drawable.pizza_100, R.string.ninosName));
tourSites.add(new TourSite(R.string.topsAddress, R.string.topsDinerNumber,
R.string.topsDinerGPS, R.string.topsWeblink, R.drawable.restaurant_100,
R.string.topsName));
tourSites.add(new TourSite(R.string.goldenEagleAddress, R.string.goldenEagleNumber,
R.string.goldenEagleGPS, R.drawable.noodles_100, R.string.goldenEagleName));
//Creates adapter that displays tourSites on tabs
TourSiteListAdapter adapter = new TourSiteListAdapter(getActivity(), tourSites);
//finds the listview that were using to display the images and names
ListView listview = (ListView) rootView.findViewById(R.id.siteList);
listview.setAdapter(adapter);
//attaches Listener to listView in order to open new activity with further
// information about the toursite
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//finds the selected list item
currentSite = tourSites.get(position);
//inflates the layout we want to display using the intent below
LayoutInflater inflater1 = (LayoutInflater) getContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View root = inflater1.inflate(R.layout.list_item_info, null, true);
//finds the textViews in the layout that we want to update before
// displaying in activity
TextView addressView = (TextView) root.findViewById(R.id.addressView);
TextView numberView = (TextView) root.findViewById((R.id.numberView));
TextView gpsView = (TextView) root.findViewById(R.id.gpsView);
TextView weblinkView = (TextView) root.findViewById(R.id.weblinkView);
//some toursites dont have phone numbers or websites. This handles that
// while also updateding the content to be displayed
if (currentSite.hasAddress()) {
addressView.setText(currentSite.getmAddress());
addressView.setVisibility(View.VISIBLE);
} else {
addressView.setVisibility(View.GONE);
}
if (currentSite.hasPhone()) {
numberView.setText(currentSite.getmPhone());
numberView.setVisibility(View.VISIBLE);
} else {
numberView.setVisibility(View.GONE);
}
gpsView.setText(currentSite.getmGPSlink());
gpsView.setMovementMethod(LinkMovementMethod.getInstance());
if (currentSite.hasWeblink()) {
weblinkView.setText(currentSite.getmWeblink());
weblinkView.setVisibility(View.VISIBLE);
weblinkView.setMovementMethod(LinkMovementMethod.getInstance());
} else {
weblinkView.setVisibility(View.GONE);
}
//used these logs to make sure the textviews were being updated correctly
Log.d("addressView = ", addressView.getText().toString());
Log.d("numberView = ", numberView.getText().toString());
Log.d("gpsView = ", "" + gpsView.getText().toString());
Log.d("weblinkView = ", weblinkView.getText().toString());
//starts new activity that displays tourSite info
Intent showInfo = new Intent(getContext(), TourSiteInfo.class);
startActivity(showInfo);
}
});
return rootView;
}
}
**This is the activity that is supposed to display the layout, but is blank
public class TourSiteInfo extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_item_info);
}
}
**This is the XML layout that is supposed to display
<LinearLayout
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"
android:orientation="vertical"
android:padding="24dp"
android:id="#+id/infoLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="#+id/addressView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="#+id/numberView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="#+id/gpsView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="#+id/weblinkView"
android:padding="16dp"/>
</LinearLayout>
***This is the mainActivity java that contains the viewPager and tabLayout
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager);
CategoryAdapter adapter = new CategoryAdapter(this, getSupportFragmentManager());
viewpager.setAdapter(adapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewpager);
}
}
**the mainAcivity XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/mainLayout">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
***LogCat when the app launches and list item is clicked
01/25 14:37:31: Launching app
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
D/addressView =: ​503 Frank E Rodgers Blvd N, Harrison, NJ 07029
D/numberView =: ​(973) 482-4883
D/gpsView =: ​(correct google link displays but stack overflow won't allow it)
D/weblinkView =: ​ginaspizzanj.com
I/Timeline: Timeline:Activity_launch_requestid
:com.example.android.tourguide
time:222869939
D/SecWifiDisplayUtil: Metadata value : none
D/ViewRootImpl: #1 mView =
com.android.internal.policy.
PhoneWindow$DecorView{d9020d4 I.E...... R.....ID 0,0-0,0}
D/ViewRootImpl: MSG_RESIZED_REPORT:
ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded
RenderNode (without mOwningView)
I/Timeline: Timeline: Activity_idle id:
android.os.BinderProxy#5ab3627 time:222870123
V/ActivityThread: updateVisibility : ActivityRecord{5e11572
token=android.os.BinderProxy#3d0da23
{com.example.android.tourguide/com.example.android.tourguide.MainActivity}} show : true
I've been researching and trying different solutions for days but nothing has worked yet.
So, I think you need to do UI initialization in TourSiteInfo class. Inflating and setting values in onItemClick doesn't make sense. It will just create a new view and will be GCed soon after the creation, the view created there doesn't have any relation with the TourSiteInfo activity.
So here is what you need to do.
Intent showInfo = new Intent(getContext(), TourSiteInfo.class);. After this you need to set all the site info to this intent as an extra value. You can refer this.
Extract info from the intent in TourSiteInfo.onCreate and set values to controls. The code will be exactly the same as you did in onItemClick.

ListView not showing up / appearing android studio

I have two activities. MainActivity.java and HomeActivity.java. I am trying to create a ListView in HomeActivity.java just with "One", "Two", "Three", and "Four" as the List items but the ListView is not showing up at all.
HomeActivity.java:
public class HomeActivity extends AppCompatActivity {
String personName;
String email;
String rfid;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
populateListView();
Bundle extras = getIntent().getExtras();
if (extras != null) {
personName = extras.getString("Name");
email = extras.getString("Email");
rfid = extras.getString("RFID");
}
String params = (email + "+" + rfid);
new MyAsyncTask().execute(new Pair<Context, String>(this, params));
toolbar.findViewById(R.id.ButtonSettings).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(HomeActivity.this, findViewById(R.id.ButtonSettings));
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
popup.getMenu().add(personName);
popup.getMenu().add(email);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(
HomeActivity.this, "You Clicked" + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
});
}
private void populateListView(){
String [] myItems = {"One", "Two", "Three", "Four"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.show_tasks, myItems);
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
}
}
content_home.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ie.myy3p.ticktask.HomeActivity"
tools:showIn="#layout/activity_home">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/profile_layout"
android:layout_below="#+id/toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tView"
android:layout_alignBottom="#id/toolbar"
android:layout_alignParentEnd="true" />
<ListView android:id = "#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
show_tasks.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
EDIT:
So I made a few changes to my code and now my ListView is showing up in content_home.xml and activity_home.xml in Android Studio, which it wasn't doing before. However, when I run the app on my phone the ListView doesn't show up. I've debugged it and checked my populateList method and it seems to be working fine. Debug at the end of populateList method reads:
this = {HomeActivity#20765}
myItems = {String[4]#20825}
adapter = {ArrayAdapter#20841}
list = {ListView#20853} "android.widget.ListView... etc
By giving a custom view to the adapter, you need an extra step to populate how that custom view uses the array adapter data to populate. The easiest solution is just ditch the custom view and use the simple list:
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
myItems);
If you want to continue to use a custom view for your cells, you'd need to create a custom adapter class that overrides getView() to tell the listview how given your string value, how it populates the view, essentially it sets the text on your textView (however this is the default behavior of android.R.layout.simple_list_item_1).
Here's a great example if you want to keep your custom view: https://stackoverflow.com/a/15832564/1316346
EDIT:
Also looks like you are inflating the wrong view:
setContentView(R.layout.activity_home);
is inflating with a resource called activity_home, from what you've posted it should probably read:
setContentView(R.layout.content_home);
Change here.
private void populateListView(){
String [] myItems = {"One", "Two", "Three", "Four"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.show_tasks, myItems);
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
}
To this
private void populateListView(){
String [] myItems = {"One", "Two", "Three", "Four"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myItems);
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
}
Alternative 2
Change set content view from this
setContentView(R.layout.activity_home);
To this
setContentView(R.layout.content_home);
It's Done.

NullPointerException getting a TextView

I am creating an extremely simple Android application to serve as a proof of concept and a reference for an application I will create in the future.
My goal is to create a ListView, each item containing a TextView and a Button that, when pressed, makes a Toast pop up displaying the content of the TextView.
Here is my code and xml:
main.xml:
<?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"
android:orientation="vertical">
<ListView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/mainListView1"/>
</LinearLayout>
entry.XML:
<?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"
android:gravity="center_vertical"
android:orientation="horizontal"
android:id="#+id/entryLayout"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/entryTextView1"
android:padding="10dp"
android:textSize="25sp"/>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#android:drawable/ic_menu_close_clear_cancel"
android:id="#+id/entryImageButton"
/>
</LinearLayout>
MainActivity.Class
public class MainActivity extends Activity{
/* Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set main.xml as user interface layout
setContentView(R.layout.main);
String[] companies = new String[] { "Test1", "Test2", "Test3",
"Test4", "Test4", "Test6", "Test7", "Test8", "Test9", "Test10"};
ArrayList<LinearLayout> views = new ArrayList<LinearLayout>();
for(int x=0; x!= companies.length-1; x++){
LinearLayout layout = (LinearLayout) findViewById(R.id.entryLayout);
TextView text = (TextView) layout.getChildAt(0);
text.setText(companies[x]);
ImageButton button = (ImageButton) layout.getChildAt(1);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
LinearLayout layout = (LinearLayout) v.getParent();
TextView view = (TextView) layout.getChildAt(0);
Toast.makeText(MainActivity.this,view.getText(), Toast.LENGTH_SHORT).show();
}
});
views.add(layout);
}
ListView listView = (ListView) findViewById(R.id.mainListView1);
for(LinearLayout layout: views){
listView.addView(layout);
}
}
I get an Kin the line
TextView text = (TextView) layout.getChildAt(0);
And for the life of me I can't figure out why. This is likely due to my lack of knowledge to how certain functions in the API work.
Your immediate issue is that findViewById looks in the layout you've inflated with setContentView() and since the Views you are trying to inflate aren't in that layout, they return null.
So this line returns null
LinearLayout layout = (LinearLayout) findViewById(R.id.entryLayout);
which causes a NPE at this line as you've noticed
TextView text = (TextView) layout.getChildAt(0);
because layout is null.
The bigger issue is the way you are going about using your ListView. Since you want to use a custom layout for the rows, you should be using a custom Adapter and inflate the appropriate layout there . You can then utilize Adapter's getView() method to set the data in each row as needed.
This tutorial can help you get started on that.
You also may want to watch Google I/O World of ListView
ListView Docs

How to create an ListView without ListActivity

Someone could tell me how can I create a ListView without using a ListActivity?
I need to put in my layout several other views, and I wish the layout was not fully occupied by the ListView. It must be part of the layout, not the entire layout. I want to create a normal Activity.
Code snippet:
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.savings);
//...
ListView lvPoupanca = (ListView)this.findViewById(R.id.lvPoupanca);
// the adapter
TestRepository repo = new TestRepository(this);
Cursor c = repo.getCursor();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item, c, new String[]{"Nome", "ValorAtual"}, new int[] {R.id.tvNome, R.id.tvValorTotal});
lvPoupancas.setAdapter(adapter);
// ...
}
Edit:
The saving.xml file:
<?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"
android:orientation="vertical" >
<ListView
android:id="#+id/lvPoupancas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
Hope somebody can help me.
Thanks and sorry about my bad english.
Like with any other View in any Activity...
ListView l = new ListView(this);
// OR
ListView l = (ListView) findViewById(R.id...);
...
l.setAdapter(...);
// If using first way: setContentView(l);
For example
I have replied to a similar question before. But that was in a different context. So, I'm putting some reference code here. It will help you to fix the issue.
public class ListandtextActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String [] str = {"ONE","TWO","THREE"};
final ListView lv = (ListView) findViewById(R.id.listView1);
final TextView tv = (TextView)findViewById(R.id.tv1);
ArrayAdapter<Object> adapt = new ArrayAdapter<Object>(getApplicationContext(), android.R.layout.simple_list_item_1, str);
lv.setAdapter(adapt);
lv.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
tv.setText("You Clicked Something");
}
});
}
}
And the XML is
<?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"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<TextView
android:id="#+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" android:textSize="20dip"/>
</LinearLayout>
By the way, before asking questions, collect as much information as possible for others to help you. If it does not work, it will be better to put the error log in the question rather than just saying it does not work.
Don't Extend ListActivity then. Extend an Activity and in onCreate() put the following code as per your requirement.
setContentView(R.layout.ur_xml);
Listview list = (ListView)findViewById(R.id.lvPoupancas);
list.setAdapter(your Adapter);

How to deal with transparent listview in Android

I have created four tabs using tabhost, and placed four listviews in each like below:
public class prem extends ListActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] names = new String[] { "Pr"};
this.setListAdapter(new ArrayAdapter<String>(this,
R.layout.simple_list_item_checked, names));
}
Problem is I have created background images for each listview but when I scroll the listview goes black.I know that I should add android:cacheColorHint="#00000000"
to the xml file to make the listview transparent, so I have created a new xml and id
and tried to add android:cacheColorHint="#00000000" in the xml to make transparent, but it just force closes;
this.setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item, R.id.listb, names));
?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">
<TextView android:text="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30px"></TextView>
<ListView android:id="#+id/listb"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
Have you tried to add setCacheColorHint(00000000) in the prem java file?
ListView lv = getListView();
lv.setCacheColorHint(00000000);
lv.setAdapter(new ArrayAdapter<String>(this,
R.layout.simple_list_item_checked, names));
android:cacheColorHint=#00000000 should do the trick. Where in your layout XML did you put it? It should go in ListView, for example:
<ListView
...
android:cacheColorHint="#00000000"
...
/>
The Android Developers' blog had a post about that a while ago. According to their post "Why is my list black? An Android optimization", all you need to do is add the android:cacheColorHint="#00000000" attribute to the ListView element.

Categories

Resources