displaying user input from edit text to list view - android

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.

Related

Handling Dynamically added Table Rows xml Layout in TableLayout Android

I have a TableLayout in fragment with following code:
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/projectsTableLayout"
android:orientation="vertical"
android:layout_margin="10dp">
</TableLayout>
This is the AddMore button which is below the TableLayout tag:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonBarButtonStyle"
android:id="#+id/add_more_projects_btn"
android:text="#string/addmore"
android:textColor="#color/colorAccent"
android:layout_below="#+id/projectsTableLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
Also I have created TableRow layout in separate xml file with following code:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:orientation="vertical">
<EditText
android:id="#+id/project_name__ET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:hint="#string/projectnametxt"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<LinearLayout
android:id="#+id/yearProjectTypeLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="05dp"
android:orientation="horizontal"
android:weightSum="1">
<Spinner
android:id="#+id/yearSpinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:drawSelectorOnTop="false"
android:spinnerMode="dropdown" />
<Spinner
android:id="#+id/projectTypeSpinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:drawSelectorOnTop="false"
android:spinnerMode="dropdown" />
</LinearLayout>
</LinearLayout>
</TableRow>
What I want to implement is when the application loads I will be dynamically add rows 5 times.
I want to add 5 more rows on the Add More button click. Also I have to send all the values to the webserver when the user moves ahead in the application.
I am confused how should provide the ID to the components like(EditText, Spinners) in the Rows of table and retrieve it when the user moves to next screen.
I want to code in such a way so it can be optimised and easy to retrieve all the data for as many rows added to TableLayout on the AddMore Button click.
How to retrieve values and set ids for Row Components.
EDIT ::
Modification of code as suggested by #Rohit Heera
I have written following code:
projectTableLayout = (TableLayout) rootView.findViewById(R.id.projectsTableLayout);
projectTableLayout.setStretchAllColumns(true);
yearAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_dropdown_item, Constants.YEAR_ARRAY);
projectTypeAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_dropdown_item, Constants.PROJECT_TYPE_ARRAY);
projectListData = new ArrayList<ProjectData>();
for(int i = 0; i < 5 ; i++)
{
tableRowStartCount = i;
TableRow projectItemRow = new TableRow(getActivity().getApplicationContext());
LayoutInflater inflator = (LayoutInflater) getActivity().getSystemService(getActivity().getApplicationContext().LAYOUT_INFLATER_SERVICE);
projectItemRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT, 1.0f));
View projectRowView = inflator.inflate(R.layout.project_row_item,projectItemRow,false);
projectNameET = (EditText) projectRowView.findViewById(R.id.project_name__ET);
yearSpinner = (Spinner) projectRowView.findViewById(R.id.yearSpinner);
yearSpinner.setAdapter(yearAdapter);
projectTypeSpinner = (Spinner) projectRowView.findViewById(R.id.projectTypeSpinner);
projectTypeSpinner.setAdapter(projectTypeAdapter);
projectItemRow.addView(projectRowView);
ProjectData projectObj = new ProjectData();
projectListData.add(projectObj);
projectTableLayout.addView(projectItemRow,tableRowStartCount);
}
Can you please let me know how can i implement the eventlistener in the above loop?
Use this code to add rows in table
/**
* this method add the dynamic table row and display the list .
*/
public void displayList(List<Data> datalist) {
int i = 0;
TableLayout projectsTableLayout = (TableLayout) findViewById(R.id.projectsTableLayout);
projectsTableLayout.removeAllViews();
for (i = 0; i <= datalist.size(); i++) {
TableRow singleTableRow = new TableRow(this);
LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.addattendeelistdata, null);
RelativeLayout parentRelativeLayout = (RelativeLayout) view
.findViewById(R.id.comleteRL);
EditText project_name__ET = (EditText) view
.findViewById(R.id.project_name__ET);
Spinner yearSpinner = (Spinner) view
.findViewById(R.id.yearSpinner);
Spinner projectTypeSpinner = (Spinner) view
.findViewById(R.id.projectTypeSpinner);
singleTableRow.addView(view);
/** Add row to TableLayout. */
projectsTableLayout.addView(singleTableRow, i);
}
}
And for get Reference for each object you need to Create seperate class .
If you tell me on which event you can move to next class so i can help you better.
Thanks
Like Edit Text you need to create separte class for spinner item listeners and store the value and main list automatically get all the new values.
/**
* this method add the dynamic table row and display the list .
*/
List<ProjectData> mainList=new List<ProjectData>();
// calling function
displayList(mainList);
public void displayList(List<ProjectData> datalist) {
int i = 0;
TableLayout projectsTableLayout = (TableLayout) findViewById(R.id.projectsTableLayout);
projectsTableLayout.removeAllViews();
for (Iterator<ProjectData> it :datalist.hasNext();) {
TableRow singleTableRow = new TableRow(this);
LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.addattendeelistdata, null);
RelativeLayout parentRelativeLayout = (RelativeLayout) view
.findViewById(R.id.comleteRL);
EditText project_name__ET = (EditText) view
.findViewById(R.id.project_name__ET);
Spinner yearSpinner = (Spinner) view
.findViewById(R.id.yearSpinner);
Spinner projectTypeSpinner = (Spinner) view
.findViewById(R.id.projectTypeSpinner);
project_name__ET.addTextChangedListener(new ListenEditText(it.next()) );
singleTableRow.addView(view);
/** Add row to TableLayout. */
projectsTableLayout.addView(singleTableRow, i);
}
}
class ListenEditText implements TextWatcher
{
ProjectData data;
ListenEditText(ProjectData data)
{
this.data=data;
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
data.project_name=s.toString();
}}
ModelClass;
class ProjectData
{
public String project_name;
public String year;
public String projectType;
}

How to Move cursor from one EditText to another one and back to the first edit text if a custom button is clicked?

i am basically developing a small mathematics app, in a activity their will be problems like additions subtractions etc. the user has to fill the answers in edittext from the custom buttons from 0-9, a dot, a slash button and a backspace button which i created on the same activity. now i like to add up and down button, so that when the up button is pressed the cursor has to move towards upside edit text and vice versa.
here is a sample code which i used
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#android:id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some string of text"
/>
<EditText
android:id="#android:id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some string of text"
/>
<Button
android:id="#android:id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
</LinearLayout>
Class:
public class Example extends Activity {
TextView et1;
TextView et2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et1 = (EditText) findViewById(android.R.id.et1);
et2 = (EditText) findViewById(android.R.id.et2);
Button button = (Button) findViewById(android.R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Selection.setSelection((Editable) et2.getText(), et1.getSelectionStart());
et2.requestFocus();
}
});
}
}
You could create an array of of your EditTexts and a variable containing your current position, defaulted to 0, meaning the first text box. Then if the user presses the up button, if the variable is greater than 0, set the position -1 and then get the textbox object from the array and call focus(). Below is an example piece of code, its not accurate but should get you started
List<EditText> textfields = null;
int currentTextFieldPosition = 0;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textfields = new ArrayList<EditText>();
textfield1 = (EditText)findViewById(R.id.textfield1);
.....
textfields.add(textfield1);
......
}
protected OnClickListener mBtnUpClickListener = new OnClickListener()
{
public boolean onClick()
{
if (currentTextfieldPosition > 0)
{
currentTextfieldPosition--;
textfields.get(currentTextFieldPosition).focus()
}
}
}

Spinner not displaying contents

so I have an app with 3 fragments. One of the fragments involves adding characters to a listview and then giving them weapons and abilities. Weapons and abilities are given to a characters via a custom dialog that appears when the Add button is clicked.
This dialog contains a spinner with a predetermined list of names of characters and then 3 edit-texts that require the user to enter the number of abilities that the characters is supposed to have.
My problem is that the spinner in this dialog is not displaying its contents.
Everytime I click on the dialog I get this :
W/InputEventReceiver﹕ Attempted to finish an input event but the input event receiver has already been disposed.
Rewards.java
public class Rewards extends Fragment {
private Button button;
Context mContext;
int lesserCount;
int greaterCount;
int exaltedCount;
Dialog addCharDialog;
Dialog lesserDialog;
Dialog greaterDialog;
Dialog exaltedDialog;
Spinner SpnLesser1;
Spinner SpnLesser2;
Spinner SpnLesser3;
Spinner SpnGreater1;
Spinner SpnGreater2;
Spinner SpnExalted;
Spinner SpnChar;
ArrayList<Character> chars = new ArrayList();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_rewards, container, false);
View addCharDialogView = inflater.inflate(R.layout.character_add, container, false);
button = (Button) rootView.findViewById(R.id.btnadd);
mContext = getActivity();
// custom dialogs
createAddDialog(addCharDialogView);
createLesserDialog();
createGreaterDialog();
createExaltedDialog();
SpnLesser1 = (Spinner) rootView.findViewById(R.id.lesserspinner1);
SpnLesser2 = (Spinner) rootView.findViewById(R.id.lesserspinner2);
SpnLesser3 = (Spinner) rootView.findViewById(R.id.lesserspinner3);
SpnGreater1 = (Spinner) rootView.findViewById(R.id.greaterspinner1);
SpnGreater2 = (Spinner) rootView.findViewById(R.id.greaterspinner2);
SpnExalted = (Spinner) rootView.findViewById(R.id.exaltedspinner);
return rootView;
}
public View createAddDialog(View addCharDialogView) {
LayoutInflater inflater = LayoutInflater.from(this.getActivity());
addCharDialog = new Dialog(mContext);
addCharDialog.setContentView(R.layout.character_add);
addCharDialog.setTitle("Add a character");
SpnChar = (Spinner) addCharDialogView.findViewById(R.id.dialog_spinner);
ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(getActivity().getBaseContext(),R.array.item_array, R.layout.spinner_layout);
//ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(addCharDialogView.getContext(),R.array.item_array, R.layout.spinner_layout);
dataAdapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
SpnChar.setAdapter(dataAdapter);
//spinner is populated but it's not displaying and won't do anything when clicked on
SpnChar.setSelection(2);
String Text = SpnChar.getSelectedItem().toString();
Log.d("2", Text);
Button dialogOkButton = (Button) addCharDialog.findViewById(R.id.dialogOK);
// if button is clicked, close the custom dialog
dialogOkButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
lesserCount = R.id.lessertext;
greaterCount = R.id.greatertext;
exaltedCount = R.id.exaltedtext;
Character c;
if (lesserCount > 0) {
lesserDialog.show();
}
if (greaterCount > 0) {
greaterDialog.show();
}
if (exaltedCount > 0) {
exaltedDialog.show();
}
}
});
Button dialogCancelButton = (Button) addCharDialog.findViewById(R.id.dialogCancel);
// if button is clicked, close the custom dialog
dialogCancelButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
addCharDialog.dismiss();
}
});
// add button listener
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
addCharDialog.show();
}
});
return addCharDialogView;
}
}
}
character_add.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--<TextView-->
<!--android:id="#+id/dialog_label"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="fill_parent"-->
<!--android:hint="Please select an option"-->
<!--/>-->
<Spinner
android:id="#+id/dialog_spinner"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<Button
android:id="#+id/dialogOK"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="OK"
android:layout_marginTop="113dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/dialogCancel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignTop="#+id/dialogOK"
android:layout_toRightOf="#+id/dialogOK" />
<EditText
android:layout_width="60dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/lessertext"
android:layout_below="#+id/dialog_spinner"
android:layout_toRightOf="#+id/editText8"
android:text="0" />
<EditText
android:layout_width="60dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/greatertext"
android:layout_below="#+id/dialog_spinner"
android:layout_toRightOf="#+id/editText9"
android:text="0" />
<EditText
android:layout_width="60dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/exaltedtext"
android:layout_below="#+id/dialog_spinner"
android:layout_toRightOf="#+id/editText10"
android:text="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText8"
android:layout_below="#+id/dialog_spinner"
android:layout_alignParentStart="true"
android:text="L" />
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/editText9"
android:layout_below="#+id/dialog_spinner"
android:layout_toRightOf="#+id/lessertext"
android:text="G" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText10"
android:layout_below="#+id/dialog_spinner"
android:layout_toRightOf="#+id/greatertext"
android:text="E" />
If I understand correctly, you want a spinner that can display the input the user types in? If so, you could use an Arraylist and create a method that will destroy your spinner and recreate it every time the contents changes. You could set it up as follows:
ArrayList<String> thing = new ArrayList<String>();
ViewGroup layout = null;
layout = (ViewGroup) spinner.getParent();
public void addSpinner(ArrayList thing){
layout.removeView(spinner);
layout.addView(spinnersy2);
spinner =(Spinner) findViewById(R.id.spinner1);
ArrayAdapter <String>adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, thing);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
Create a second method that will add the user input into the array.

Print lines in Listview using an adapter

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.

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