For some reason setCurrentTab is not switching tabs after the first time.
This is the code that I use.
private OnClickListener buttonListener = new OnClickListener(){
#Override
public void onClick(View v) {
tabHost.setCurrentTab(Integer.parseInt((String) v.getTag()));
}
};
It is connected to buttons each of which have a tag that equals the number of of tab to be shown.
When the button is clicked the first time and this method is called then the tab shows up. I can also see that it executes the code that creates the tab contents.
However, once a tab has been shown once and I have moved to another one, clicking back to it doesn't work.
The method is definitely called and the tag is also correct. I put in commands to print to the log to confirm that. Also, it works first time round so must be okay.
Any idea?
Full code:
public class TestTabs extends TabbedScreen implements TabHost.TabContentFactory{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initTabs();
}
#Override
protected void initTabs() {
addTab("0",this);
addTab("1",this);
addTab("2",this);
addTab("3",this);
}
/*
*
* #param extras The Bundle received in onCreate when this class is first created, and which contains the initial set of objects to be displayed.
* #return An array containing all of the objects in the list.
*/
protected Serializable[] getDataArray(Bundle extras) {
int size = extras.size();
Serializable[] data = new Serializable[size];
for (int i = 0; i < size; i++) {
data[i] = extras.getSerializable(Integer.toString(i));
}
return data;
}
#Override
public View createTabContent(String tag) {
// Get the data returned from the servelet and display it in the ListView
Log.d("TestTabs","createTabContent");
ListView lv = (ListView) findViewById(R.id.list_view);
List<String> list1Strings = new ArrayList<String>();
switch (Integer.parseInt(tag)){
case 0:
Log.d("TestTabs","Case 0");
lv.setAdapter(new MyAdapter(this,lv,null));
break;
case 1:
Log.d("TestTabs","Case 1");
list1Strings.add("Item 21");
list1Strings.add("Item 22");
list1Strings.add("Item 23");
list1Strings.add("Item 24");
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
break;
case 2:
Log.d("TestTabs","Case 2");
list1Strings.add("Item 31");
list1Strings.add("Item 32");
list1Strings.add("Item 33");
list1Strings.add("Item 34");
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
break;
case 3:
Log.d("TestTabs","Case 3");
list1Strings.add("Item 41");
list1Strings.add("Item 42");
list1Strings.add("Item 43");
list1Strings.add("Item 44");
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
break;
}
return lv;
}
protected void addTab(String tabName, TabHost.TabContentFactory tabFactory){
TabSpec tabSpec = tabHost.newTabSpec(tabName);
tabSpec.setIndicator(tabName); // Don't set tab layout since we are going to make it invisible
tabSpec.setContent(tabFactory);
tabHost.addTab(tabSpec);
addButton(tabName);
}
protected void addButton(String tabName){
Button button = (Button) buttonHolder.getChildAt(nextChild);
button.setText(tabName);
button.setVisibility(View.VISIBLE);
button.setOnClickListener(buttonListener);
nextChild--;
}
private OnClickListener buttonListener = new OnClickListener(){
#Override
public void onClick(View v) {
v.setBackgroundResource(R.drawable.tab_selected);
tabHost.setCurrentTab(Integer.parseInt((String) v.getTag()));
Log.d("TabbedScreen","Set tab to " + v.getTag());
View view;
for (int i=0; i< childCount; i++)
if ((view = buttonHolder.getChildAt(i)) != v){
view.setBackgroundResource(R.drawable.button_tab);
view.invalidate();
}
}
};
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:roundedListView="http://schemas.android.com/apk/res/com.applicat.meuchedet"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/content_screen_user_details">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="#android:id/tabs" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:visibility="gone"/>
<LinearLayout android:id="#+id/tabButtons" android:layout_width="wrap_content" android:layout_height="20dip">
<Button android:layout_height="wrap_content" android:layout_width="0dip"
android:layout_weight="1.0" android:id="#+id/button3"
android:background="#drawable/button_tab" android:visibility="invisible"
android:tag="3"/>
<Button android:layout_height="wrap_content" android:layout_width="0dip"
android:layout_weight="1.0" android:id="#+id/button2"
android:background="#drawable/button_tab" android:visibility="invisible"
android:tag="2"/>
<Button android:layout_height="wrap_content" android:layout_width="0dip"
android:layout_weight="1.0" android:id="#+id/button1"
android:background="#drawable/button_tab" android:visibility="invisible"
android:tag="1"/>
<Button android:layout_height="wrap_content" android:layout_width="0dip"
android:layout_weight="1.0" android:id="#+id/button0"
android:background="#drawable/tab_selected" android:visibility="invisible"
android:tag="0"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.applicat.meuchedet.views.RoundedListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:dividerHeight="1dip"
android:footerDividersEnabled="true"
android:listSelector="#drawable/listview_selected_item_background"
android:fadingEdge="none"
android:cacheColorHint = "#00000000"
roundedListView:radius="20"
roundedListView:border="2"
/>
</FrameLayout>
</LinearLayout>
</TabHost>
Edit:
I was wondering if the problem is in the row:
ListView lv = (ListView) findViewById(R.id.list_view);
Am I getting back the same object each time?
If so, how do I get a new one each time based on the one defined in the FrameLayout.
How can you be sure that the value assigned to button in your xml is the same you get with only nextChild-- .
not so good solution, you can test it.
void addButton(String tabName){
Button button = (Button) buttonHolder.getChildAt(nextChild);
button.getTag() != String.valueOf(nextChild); ERROR;
but It's better to set it to the same as you always get with buttonHolder.getChildAt()
Button button = (Button) buttonHolder.getChildAt(nextChild);
button.setTag(String.valueOf(nextChild));
modified:
protected void addButton(String tabName){
Button button = (Button) buttonHolder.getChildAt(nextChild);
// ----------- modified -----------
button.setTag(String.valueOf(nextChild));
button.setText(tabName);
button.setVisibility(View.VISIBLE);
button.setOnClickListener(buttonListener);
nextChild--;
}
private OnClickListener buttonListener = new OnClickListener(){
#Override
public void onClick(View v) {
v.setBackgroundResource(R.drawable.tab_selected);
// ----------- modified -----------
Button btc = (Button)v;
int idx;
try {
idx = Integer.parseInt((String) btc.getTag());
} catch(NumberFormatException exx) {
System.out.println("Could not parse " + exx);
}
if ( idx < childCount) {
Log.d("TabbedScreen","Set tab to " + String.valueOf(idx);
Button butv;
for (int i=0; i< childCount; i++)
if ( i != idx){
butv = (Button) buttonHolder.getChildAt(i);
butv.setBackgroundResource(R.drawable.button_tab);
butv.invalidate();
}
tabHost.setCurrentTab(idx);
tabHost.focusCurrentTab(idx);
}
// ----------- modified -----------
}
};
}
In order to use getTag, you must need to set it first. So I believe you forgot to add the following line in your addButton method:
button.setTag(tabName);
use this
ListView lv = getListView();
instead of
ListView lv = (ListView) findViewById(R.id.list_view);
The getListView() method returns the the list view associated with the 'current' layout.
Also, for this to work you have to change the list view's id in the xml as
<ListView
android:id="#+android:id/list"
may be getTag() creating the problem just store its return value in variable an check if the value is correct (the integer no you actually want)??
Related
I'm developing with android studio.
I have a ListView that the elements in it are aligned from left to right and I want to align them from right to left, how can I do so?
the java class is:
public class ProductList extends ListActivity {
ArrayList<String> list = new ArrayList<String>(Arrays.asList("במבה אוסם", "בשר טחון", "קוקה קולה שישייה", "קפה עלית", "שמיר", "מילקי","רבעיית דניאלה"));
ArrayAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pop_productlist);
Button btnDel = (Button) findViewById(R.id.btnDel);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, list);
/** Defining a click event listener for the button "Delete" */
View.OnClickListener listenerDel = new View.OnClickListener() {
#Override
public void onClick(View v) {
/** Getting the checked items from the listview */
SparseBooleanArray checkedItemPositions = getListView().getCheckedItemPositions();
int itemCount = getListView().getCount();
for(int i=itemCount-1; i >= 0; i--){
if(checkedItemPositions.get(i)){
adapter.remove(list.get(i));
}
}
checkedItemPositions.clear();
adapter.notifyDataSetChanged();
}
};
/** Setting the event listener for the delete button */
btnDel.setOnClickListener(listenerDel);
/** Setting the adapter to the ListView */
setListAdapter(adapter);
}
public void StartCalck(View view){
Intent intent = new Intent(ProductList.this, SplitBuying.class);
startActivity(intent);
}
}
and the layout is:
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
android:layout_below="#+id/ChooseStore">
</ListView>
</LinearLayout>
Thank you !
Use RecyclerView instead of ListView.
LinearLayoutManager(Context context, int orientation, boolean reverseLayout)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" ><br>
<TextView
android:id="#+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/><br>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_toLeftOf="#+id/textView_name"/>
</RelativeLayout>
Manifest.xml
<application
....
android:supportsRtl="true"
...
</application>
you should use custom layout like
myTextView.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:gravity="right"
android:background="#bdbdbd"/>
pass this layout to adapter like
ArrayAdapter adapter = new ArrayAdapter(this,R.layout.nameOfLayout, list);
My listview doesnt seem to show on screen.
I'm using a tabhost and put a list in a frame but for some reason it's not working.
I'm sure my code seems right so am unsure what's wrong here..
Help please!
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabhost">
<LinearLayout
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="List"
android:id="#+id/listtext"
android:layout_gravity="center_horizontal" />
<TabWidget
android:id="#android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView
android:id="#+id/list"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
</ListView>
</FrameLayout>
</LinearLayout>
</TabHost>
Tab 1 Code:
public class WorkoutDay1 extends Activity {
ListView listView ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.workoutlist_main);
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values = new String[] { "Chest Press",
"Shoulder Press",
"Arm Extension",
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/* // ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);*/
// Show Alert
if(position == 0) {
//code specific to first list item
Intent myIntent = new Intent(view.getContext(), workout.class);
startActivityForResult(myIntent, 0);
}
if(position == 1) {
//code specific to 2nd list item
Toast.makeText(getApplicationContext(),
"Coming Soon.", Toast.LENGTH_SHORT)
.show();
}
if(position == 2) {
//code specific to 2nd list item
Toast.makeText(getApplicationContext(),
"Coming Soon." , Toast.LENGTH_SHORT)
.show();
}
}
});
}
}
You hvnt posted your complete code but I am just guessing that you might not have called notifyDataSetChanged() after assigning data to your list..
Does anyone know how I could create a for loop(?) for my imageView and textView without adding them in my XML file? I'm not sure if it is possible too..so I would appreciate if someone could help me in this.
For your info, I would like to grab data from another activity. eg. If the user click the add to Favourite button, I would display another imageView & textView in this activity of the clothes image and name. The activity will also display the previous items that is added to the page.
XML file:
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/name"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="a" />
</LinearLayout>
Inside my onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_favourite);
editButton = (Button)findViewById(R.id.edit);
image = (ImageView)findViewById(R.id.image);
name = (TextView)findViewById(R.id.name);
}
Thank you.
I think what you are going to want to do is in your layout have a ListView, and then you create something that implements ListAdapter (ArrayAdapter is a good choice). In your adapter you can reuse one xml file that would contain your ImageView and TextView.
There are a lot of good tutorials out there on it, Googling "ListView Adapter" will get you pretty far. Here's a good one: http://www.vogella.com/articles/AndroidListView/article.html
Yours is a pretty simple case, so you can use an ArrayAdapter like this:
Activity:
public class MainActivity extends Activity {
private ArrayAdapter<String> listAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>()) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null)
{
v = super.getView(position, convertView, parent);
}
String text = getItem(position);
TextView textview = ((TextView) v.findViewById(android.R.id.text1));
textview.setText(text);
// Now you can set an image by calling
// textview.setCompoundDrawablesWithIntrinsicBounds(...);
return v;
}
};
((ListView) findViewById(R.id.listView)).setAdapter(listAdapter);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
private int i = 0;
#Override
public void onClick(View view) {
listAdapter.add("item number: " + (++i));
listAdapter.notifyDataSetChanged();
}
});
}
}
Layout activity_main:
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
tools:listitem="#layout/listview_row"
android:layout_above="#+id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Alternative:
If you are bent on not using a ListView or for whatever reason you can't use a list view, you can always inflate a layout and add it to another layout in your app. The code below would then replace the code above in the button's on click:
View row = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); /* null here means it's not attaching/populating a view you already have */
((TextView) row.findViewById(android.R.id.text1)).setText("item number: " + (++i));
((ViewGroup) findViewById(R.id.linearlayout)).addView(row);
findViewById(R.id.linearlayout).invalidate();
Using a ListView here is the right way to go, so this is kind of a last resort.
I'm not sure of what you want, maybe this?
for (int i = 1; i <= 20; i++) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button btn = new Button(this);
btn.setId(i);
final int id_ = btn.getId();
btn.setText("button " + id_);
btn.setBackgroundColor(Color.rgb(70, 80, 90));
linear.addView(btn, params);
btn1 = ((Button) findViewById(id_));
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(view.getContext(),
"Button clicked index = " + id_, Toast.LENGTH_SHORT)
.show();
}
});
}
I need to output data from lines cm1 and cm2 in a ListView, every time when I press the button. Line should be shown in various TextView.
Code TEST.java:
public String cm1;
public String cm2;
public class TEST extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyList = (ListView) this.findViewById(R.id.listStrings);
setListAdapter();
// button
Button setup = (Button) this.findViewById(R.id.send);
setup.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
cm1 = "cm1text";
cm2 = "cm2text";
//xxxx
}
});
}
// adapter
private void setListAdapter() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row //idknow what im must writehere to set cm1 string to cm1text tv
List.setAdapter(adapter);
}
Code TEST.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:id="#+id/listStrings"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
Code row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/cm1tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/cm2tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Should look ListView after 2 clicks:
cm1
cm2
cm1
cm2
Maybe what you should/can do is have this;
String cm = cm1 + "\n" + cm2
Which should output;
cm1
cm2
Then you change the xml to just have one textview and the adapter code as follows;
ArrayList<String> listItems = new ArrayList<String>();
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.row, R.id.textViewCM, listItems);
yourListView.setAdapter(aa);
Then, whenever you press the button;
// ...code to initialise/change cm
listItems.add(cm);
aa.notifyDataSetChanged(); // notifies listView to update it's view
That should do what you're after unless you've got to have the two individual textViews, in which case, you'll need to write a custom adapter, I've done a bit of a tutorial on my website if you follow that link.
I have a white background but with this layout i am blocked because text color is white too and i can't find a solution to make it red so i can set my white background, any help please (as u can see i am forced to use a red background her so i can see the white text).
public class QueueListActivity extends ListActivity {
// LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
ArrayList<String> listItems = new ArrayList<String>();
String newtext;
String listFiles;
// DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW
ArrayAdapter<String> adapter;
// RECORDING HOW MUCH TIMES BUTTON WAS CLICKED
int clickCounter = 0;
ArrayList<String> selectedItems = new ArrayList<String>();
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.queuelistactivity);
Bundle extras1 = getIntent().getExtras();
listFiles=GetFiles();
StringTokenizer tokonizer1 = new StringTokenizer(listFiles,";");
while(tokonizer1.hasMoreElements()){
Log.i("verif","0");
listItems.add(tokonizer1.nextToken());}
initializeListItems();
if (extras1 != null) {
newtext = extras1.getString("newitem");
listItems.add(newtext);
adapter.notifyDataSetChanged();
getListView().setItemChecked(listItems.size() - 1, false);
}
}
// METHOD WHICH WILL HANDLE DYNAMIC INSERTION
public void addItems(View v) {
Intent intent = new Intent(QueueListActivity.this, AjouterFiles.class);
QueueListActivity.this.startActivity(intent);
/*
listItems.add(userName);
adapter.notifyDataSetChanged();
getListView().setItemChecked(listItems.size() - 1, false);*/
}
public void deleteItems(View v) {
String toDelete = "";
SparseBooleanArray sp = getListView().getCheckedItemPositions();
for (int i = 0; i < sp.size(); i++) {
toDelete += ";" + sp.get(i);
if (sp.get(i)) {
listItems.remove(i);
}
}
adapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), toDelete, Toast.LENGTH_LONG).show();
initializeListItems();
}
private void initializeListItems() {
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, listItems);
setListAdapter(adapter);
ListView lv = getListView();
lv.setCacheColorHint(Color.rgb(0, 0, 0));
lv.setBackgroundColor(Color.rgb(178, 34, 34));
for (int i = 0; i < lv.getCount(); i++) {
lv.setItemChecked(i, false);
}
}
Best trick is you copy content layout file from android.R.layout.simple_list_item_multiple_choice and make your own layout(my_list_view and edit the xml file and change the text color.
adapter = new ArrayAdapter(this,my_list_view, listItems);
Edit save this file as my_list_view;
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:background="#FFFFFF" //white background
android:textColor="#000000" //black color text
/>
android:textColor="#android:color/white"
You can set it in the XML layout:
<TextView
...
...
android:textColor="#FF0000" >
</TextView>
Or programmatically:
textview.setTextColor(Color.RED);
//textview must be defined in your class
better to write custom adpter .
alternate but not good soltuon is use this layout xml inspace of android.R.layout.simple_list_item_multiple_choice
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textColor= Color.Red //please correct the syntax
/>
This is same android.R.layout.simple_list_item_multiple_choice layout but your are now making same in your layouts with same ids to make the changes in it.
you can try custom list view.. follow the link click here
<TextView
android:id="#+id/text_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Name"
android:textColor="#color/white"
android:textSize="11dp"
/>