Changing the text color - android

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"
/>

Related

align listview from right to left

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

TextView Color in the Spinner

What i want is the Text color of the spinner should be white at runtime when it is displayed inside the Spinner as it is in spinner 1 and 2 and the text color of the list of Spinner should be black as in the picture.
The problem is i am able to do it for the first 2 Spinners but fail to do it for the 3rd and the 4th Spinner.
If you can see the 3rd and 4th Spinner has values but in black. I don't understand that if its possible for 2 spinners then y not for all 4. please help me.
This is my code to change color at runtime:
public class Text // class for changing the text color of spinner
{
private TextView tv = null;
Text(View spin_adptr)
{
tv = (TextView) spin_adptr.findViewById(R.id.textspin);
tv.setTextColor(Color.WHITE);
}
}
and this is how i am calling it:
public void onItemSelected(AdapterView<?> parent, View arg1, int position,
long arg3) {
int id = parent.getId();
Text text = new Text(spinner1); //Change of color (Working)
Text text1 = new Text(spinner3); //Change of Color(ERROR)
Text text2 = new Text(spinner4); //Change of Color(ERROR)
switch (id) {
case R.id.spinner1:
String b = spinner1.getSelectedItem().toString();
if (b != null) {
dbCarHelper.make_pop(b);
}
List<String> lb = h.getAllLabels();
ArrayAdapter<String> dAdapter = new ArrayAdapter<String>(this,
R.layout.spin_adptr,lb);
dAdapter.setDropDownViewResource(R.layout.spin_adptr);
spinner2.setAdapter(dAdapter);
break;
case R.id.spinner2:
Text text1 = new Text(spinner2); //// Change of color (working)
String a = spinner2.getSelectedItem().toString();
if (a != null) {
dbCarHelper.m_pop(a);
}
CarHelper c = new CarHelper(getApplicationContext());
List<String> lable = c.getAllLabel();
ArrayAdapter<String> dAdaptr = new ArrayAdapter<String>(this,
R.layout.spin_adptr,lable);
dAdaptr.setDropDownViewResource(R.layout.spin_adptr);
spinner3.setAdapter(dAdaptr);
break;
}
}
make a xml file named as spinner_layout and write code as below
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:ellipsize="marquee"
android:singleLine="true" />
make another xml named as spinner_dropdown and write below code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:textSize="18sp"
android:textColor="#000000"
android:ellipsize="marquee"
android:singleLine="true" />
now update your code as below
ArrayAdapter<String> dAdapter = new ArrayAdapter<String>(this,
R.layout.spinner_layout,lb);
dAdapter.setDropDownViewResource(R.layout.spinner_dropdown);

displaying user input from edit text to list view

I have problem with adding 2 numbers in list view. This is my row with 2 text view (for each numer). textView2 ignore
<?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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
When user add number it will display in list view. That second number needs to be 11 - that number that user inserted. It's all working but I dont know how to display that second number.
public class MainActivity extends Activity {
ArrayAdapter<String> m_adapter;
ArrayList<String> m_listItems = new ArrayList<String>();
Button bt;
EditText et;
TextView tv;
ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Inflate the menu; this adds items to the action bar if it is present.
bt = (Button) findViewById(R.id.button1);
et = (EditText) findViewById(R.id.editText1);
tv = (TextView) findViewById(R.id.textView1);
lv = (ListView) findViewById(R.id.lista);
m_adapter = new ArrayAdapter<String>(this,R.layout.row, R.id.textView1);
lv.setAdapter(m_adapter);
//final String input = et.getText().toString();
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String input = et.getText().toString();
if(null!=input&&input.length()>0){
String maxpunti = "11";
int a = Integer.parseInt(maxpunti);
int b = Integer.parseInt(input);
int c = a-b;
String input2 = String.valueOf(c);
m_adapter.add(input);
m_adapter.add(input2);
m_adapter.notifyDataSetChanged();
}
}
});
}
}
The default implementation of ArrayAdapter<String> binds a single Stringvalue to a a single textfield. Since you have several views for each listitem or "row" in your listview ( you need to implement/extend your own ArrayAdapter and override the getView method.
Them you can set the values for any number of custom views that you may have in your list item layout.
Look at a simple example and also it might be a good idea to look som docs on how listviews/adpters work in android since they are very central.

Android - how do I place an image in one of the columns of a 2-column list and center the image vertically?

I have a 2-column row layout that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="25dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/arrow_button"/>
</LinearLayout>
And once I fetch items from the database, I display them in the left column, and in the right column I want to have a little image with an arrow signifying that it is a clickable item. But I am not sure how to make the image render. Here is how I currently populate that list:
I have these two variables:
private List<HashMap<String, String>> fillMaps;
private SimpleAdapter adapter;
At first I set them up like this:
list = (ListView) findViewById(android.R.id.list);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
//HashMap<String, String> map = new HashMap<String, String>();
// My data
fillMaps = new ArrayList<HashMap<String, String>>();
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train", "to"},
new int[] {R.id.TRAIN_CELL, R.id.TO_CELL});
// This was the middle item R.id.FROM_CELL,
list.setAdapter(adapter);
list.setTextFilterEnabled(true);
and when the data comes back from the server, I populate the list like this:
if ( obj != null )
{
questions.clear();
for ( int i = 0; i < obj.length(); i++ )
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject o = obj.getJSONObject(i);
question_id = o.getString("question_id");
question = o.getString("question");
question_by_member_id = o.getString("member_id");
Question q = new Question ( );
q.setQuestion( question );
q.setQuestionId( question_id );
q.setQuestionByMemberId(question_by_member_id);
map.put("train", question);
//map.put("from", ">");
//map.put("to", ">");
fillMaps.add(map);
questions.add( q );
}
adapter.notifyDataSetChanged();
}
But I am not getting the image to render. I think part of the problem is that I am using Strings as the data that the list expects, but I am not sure how to handle this with the images. The image is always the same image by the way.
Thanks!! :)
Is this what you want?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="25dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/arrow_button"/>
</LinearLayout>
Addition
(Sorry, sometimes I miss notifications when they pile up over night. I believe you should be able to read messages / remove notifications here on Stack Overflow one by one or all at once, like an inbox...)
Anyway, if TO_CELL's image is always going to be the same, simply set the image in the XML only. Change your SimpleAdapter to this:
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train"},
new int[] {R.id.TRAIN_CELL});
Now your adapter only handles one string, you can simplify it to an ArrayAdapter (if you want.)
Simplified Example
You can also display one TextView and display a small "next" arrow like so:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#android:drawable/ic_media_play"
android:padding="10sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
(A LinearLayout and separate ImageView is not strictly necessary. I saved this as list_item.xml.)
Here is a simple preview, understand that I left a lot of the non-critical lines out to not be repetitive:
public class Example extends Activity {
ArrayAdapter<String> adapter;
List<String> list = new ArrayList<String>();
ListView listView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, list);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
updateList();
}
public void updateList() {
...
if ( obj != null ) {
questions.clear();
list.clear();
for ( int i = 0; i < obj.length(); i++ ) {
JSONObject o = obj.getJSONObject(i);
...
question = o.getString("question");
list.add(question);
}
adapter.notifyDataSetChanged();
}
}
}
Hope this helps!
I believe the easiest way is instead of using a SimpleAdapter try extending the ArrayAdapter for your needs. You can override the getView() method and populate your list the way you need!
There are a few examples here, here and here.
EDIT
First, you need a few modifications in your xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="#+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="#+id/TO_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#fff"/>
</LinearLayout>
In the following code I used a ArrayList of Strings for simplicity. You will have to replace that with a list of whatever object you are using to populate your list. (Question maybe?)
Create an ExtendedAdapter and override the getView() method to do what you intend. This will create a TextView and a ImageView on each row of the list, populate the TextView with the items in your ArrayList items and show the image if the item is clickable. (You have to do the verification by yourself but shouldn't be hard to figure it out)
public class ExtendedAdapter extends BaseAdapter {
public static final String TAG = "TodoAdapter";
private Context mContext;
private int layoutResource;
private boolean clickable = false;
private List<String> items; // you can replace this list with whathever you need
// for simplicity i'm assuming you already have the strings
// you need for the textviews
public ExtendedAdapter(Context context, int textViewResourceId,
List<String> items) {
this.items = items;
this.mContext = context;
this.layoutResource = textViewResourceId;
}
public int getCount() {
return items.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(layoutResource, null);
}
ImageView arrow = (ImageView) v.findViewById(R.id.TO_CELL);
TextView text = (TextView) v.findViewById(R.id.TRAIN_CELL);
text.setText(items.get(position));
if (clickable) // here you have to do your check if it's clickable or not
arrow.setBackgroundResource(R.drawable.ic_launcher);
return v;
}
}
And in your activity, just set the list adapter
public class MainActivity extends Activity {
ListView yourList;
ArrayList<String> itemList = new ArrayList<String>();
ExtendedAdapter adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
yourList = (ListView) findViewById(R.id.yourList);
adapter = new ExtendedAdapter(this, R.layout.row_layout, itemList);
yourList.setAdapter(adapter);
updateItems();
}
public void updateItems(){
//dummy method, you should fetch your data and populate your array in a separate thread
//or something
itemList.add("Text 1");
itemList.add("Text 2");
itemList.add("Text 3");
itemList.add("Text 4");
itemList.add("Text 5");
itemList.add("Text 6");
adapter.notifyDataSetChanged();
}
}
That's how you create a list with text and image.
Good luck!
I think you should customize the list adapter and it will be easy this way.
The problem is with Layout and with the Simple adpater.
1.do not use linearLayout android:textSize="13sp" use it for TextView,
you can use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:id="#+id/TRAIN_CELL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="try out by yourself..."
android:textSize="13sp" />
<ImageView
android:id="#+id/TO_CELL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".05"
android:gravity="center"
android:src="#android:drawable/arrow_down_float" />
</LinearLayout>
2.The problem is in SimpleAdapter use
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train"},
new int[] {R.id.TRAIN_CELL});

Selecting checbox and textitem in custom listview it doesn't works fine

I've done a Custom Listview with 3 columns:
Product / Selected (check box)/ Quantity.
The first column i've get from sqllite database. And second and third column, i'll write into a database.
I've the problem that when i write into qunatity column the checkbox i've checked is unchecked, and it doesn't work.
Another problem is when select edittext to write a quantity the checkbox selections changes.
//productos.java
Button btComanda = (Button) findViewById(R.id.btComanda);
btComanda.setOnClickListener(new OnClickListener() {
public void onClick (View arg0) {
Log.v("Escriu Comanda", "inici");
final ListView prodSpinner = (ListView) findViewById(R.id.list);
final CheckBox cbArticle = (CheckBox) findViewById(R.id.TextView02);
final TextView txtQuantitat = (TextView) findViewById(R.id.TextView03);
int count = 0;
Log.v("Escriu Comanda 2",String.valueOf(prodCursor.getCount())+ " " + txtQuantitat);
for(int i = 0; i < prodCursor.getCount(); i++)
{
Log.v("inserta 1", String.valueOf(Producte)+ " " + cbArticle.isChecked());
Producte = i;
String a = prodSpinner.getItemAtPosition(i).toString();
InsertaComanda();
});
recCatSpinner();
}
public void recProdSpinner() {
ListView prodSpinner = (ListView) findViewById(R.id.list);
prodCursor = recuperaProductos();
prodSpinner.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
prodAdapter = new ArrayAdapter<String>(this, R.layout.listview, R.id.TextView02);
prodAdapter.setDropDownViewResource (R.layout.listview_item_row);
prodSpinner.setAdapter(prodAdapter);
if (prodCursor.moveToFirst()) {
do {
prodAdapter.add(prodCursor.getString(1));
}
while (prodCursor.moveToNext());
if (db != null) {
db.close();
}
}
startManagingCursor(prodCursor);
prodCursor.close();
prodSpinner.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int pos, long id) {
}
});
}
The xml file:
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="10.77" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</TextView>
<CheckBox
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/TextView02"
android:focusable="false" />
<EditText
android:id="#+id/TextView03"
android:layout_width="138dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
</TableLayout>
</LinearLayout>
Read about how ListViews work and you will understand why its happening - the ListView is populating each row when it appears on the screen (so your values and states will change when you scroll)
so what you need to do is to save the state at the moment the user is changing it to somewhere safe - array / database etc.. and when you load it under your custom list adapter you need to change the state into the right one
so for your checkboxs you need to implement a listener and save its state when it is changing and under getView you need to set the specific CheckBox to its saved state .
the thing is EditTexts inside ListViews is pretty damn problematic but it is possible if you are stubborn enough.
hope it helps and tell me if you need any more help.
in addition to
android:focusable="false"
add this also..
"android:clickable="false""
i think it works.. let me know if it doesn't..

Categories

Resources