Friday, February 14, 2014

EditText ListView in solving problems


I used the program in android ListView displays a table which has a table entry is EditText, but now there are two problems:
After 1.EditText finished editing, click on the back button content disappears.
2 How to get content EditText (and know that it is the first few lines).
Seek expert answers.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
1:
more info
2:
In the adapter, there getView, can position the item to operate.
Reply:
Can specific point, I was a rookie.
My code:
ScoreInformation.java

public class ScoreInformation extends Activity {
private ListView lv;
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);

ArrayList > mylist = new ArrayList > ();
HashMap map = new HashMap ();
map.put ("ID", "Student ID");
map.put ("Name", "name");
map.put ("Course", "subject");
map.put ("Score", "result");
mylist.add (map);
for (int i = 0; i int j = 0;
HashMap map1 = new HashMap ();
map1.put ("ID", Datainfo.data [j + +] [i]);
map1.put ("Name", Datainfo.data [j + +] [i]);
map1.put ("Course", Teacherinfo.course);
if (Datainfo.data [j + +] [i]. equals ("null")) {
map1.put ("Score", "");
} Else {
map1.put ("Score", Datainfo.data [j + +] [i]);
}
mylist.add (map1);
}

SpecialAdapter adapter = new SpecialAdapter (this, mylist, R.layout.scoreinformation,
new String [] {"ID", "Name", "Course", "Score"},
new int [] {R.id.tv1, R.id.tv2, R.id.tv3, R.id.tv4}
);

lv = new ListView (this);
lv.setHorizontalScrollBarEnabled (true);
lv.setAdapter (adapter);
HorizontalScrollView hsv = new HorizontalScrollView (this);
hsv.addView (lv);
setContentView (hsv);
}
}
Where "tv4" is the record score EditText

SpecialAdapter.java
public class SpecialAdapter extends SimpleAdapter {
private int [] colors = new int [] {
0x30FF0000, 0x300000FF
};
public SpecialAdapter (Context context, List > data,
int resource, String [] from, int [] to) {
super (context, data, resource, from, to);
/ / TODO Auto-generated constructor stub
}

@ Override
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView (position, convertView, parent);
int colorPos = position% colors.length;
if (colorPos == 1) {
view.setBackgroundColor (Color.argb (250, 255, 255, 255));
} Else {
view.setBackgroundColor (Color.argb (250, 224, 243, 250));
}
return view;
}
}
Reply:
public View getView (int position, View convertView, ViewGroup parent) {
-------------------------------------------------- ----------------------
Here plus listener like the listener in treatment
Reply:
The reply was deleted at the moderator 2011-04-12 11:20:41

Reply:
In public View getView (int position, View convertView, ViewGroup parent) to add the inside of the EditText modification function, so you can get which is modified, what changes is the
Reply:
Create an EditText of two-digit group and then use a for loop dynamic layout for each array member setTag (key, value); You can set each of the relevant information, then you can listen
Reply:
2, you must be an event listener listview is it, this is it, there will be a parameter representative of the item to which you were clicking, this parameter is the position you want, oh
Reply:
We are uncertain tangled ah ah!
Reply:
reference to the 7th floor sky123123 reply:
2, you must be an event listener listview is it, this is it, there will be an argument on behalf of you to which item has been clicked, this parameter is the position you want, oh


Thank you for reminding me tried OnItemClickListener, but he did not call this is what happens?
Reply:
reference to the 6th floor dumbrock reply:
create an EditText of two-digit group and then use a for loop dynamic layout for each array member setTag (key, value ); You can set each of the relevant information, then the listener can

This ...... I use the loop dynamic layout but the whole cycle all EditText ListView are used "tv4" this id
Reply:
ListView I would not do this now in the form of a bunch of disgusting I did not use dynamic layout ListView how to draw me back on how I painted the table and then add
class of manually scroll bar
reference to the 10th floor dlut_labor reply:
reference to the 6th floor dumbrock reply:

Create an EditText of two-digit group and then use a for loop dynamic layout for each array member setTag (key, value); You can set each of the relevant information, then the listener can

This ...... I use the loop dynamic layout but the whole cycle all EditText ListView are used "tv4" The id

Reply:
You see a piece of code probably mean
 
for (int j = 0; j et [i] [j] = new EditText (c);
et [i] [j] setTag (R.string.flag, null);.
. et [i] [j] setTag (. R.string.colsname, s.params.get (j) col);

et [i] [j] setTag (R.string.max, s.params.get (j) max.);.
et [i] [j] setTag (R.string.min, s.params.get (j) min.);.
et [i] [j] setTag (R.string.pcs, s.params.get (j) pcs.);.
et [i] [j] setTag (R.string.tpy, s.params.get (j) tpy.);.

et [i] [j] setTag (R.string.id, id);.
et [i] [j] setTextSize (Devicer.getFontNormal ());.

if (j == colcount-1 && flag) {
et [i] [j] setTag (R.string.max, String.valueOf (Integer.MAX_VALUE));.
}

layout.addView (et [i] [j], width / (colcount +1) +20, Devicer.getTextViewHeight ());

if (s.params.get (j). tpy.equals ("N")) {
. et [i] [j] setInputType (InputType.TYPE_CLASS_NUMBER);
. et [i] [j] setText ("0");
if (Integer.valueOf (s.params.get (j). pcs)> 0) {
et [i] [j] setInputType (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);.
}
}

if (s.params.get (j). tpy.equals ("L")) {
et [i] [j] setEnabled (true);.
. et [i] [j] setText ("0");
et [i] [j] setInputType (InputType.TYPE_NULL);.
et [i] [j] setEnabled (false);.
et [i] [j] setClickable (false);.

}

DTextWatcher watcher = new DTextWatcher (et [i] [j], handler);
et [i] [j] addTextChangedListener (watcher);.
et [i] [j] setImeOptions (EditorInfo.IME_ACTION_UNSPECIFIED);.

et [i] [j]. setOnFocusChangeListener (new OnFocusChangeListener () {
public void onFocusChange (View view, boolean hasChange) {

if (view.getTag (R.string.tpy). equals ("L")) {
view.setClickable (false);
return;
}

}
}
});
}


reference to the 10th floor dlut_labor reply:
reference to the 6th floor dumbrock reply:

Create an EditText of two-digit group and then use a for loop dynamic layout for each array member setTag (key, value); You can set each of the relevant information, then the listener can

This ...... I use the loop dynamic layout but the whole cycle all EditText ListView are used "tv4" The id

Reply:
reference to the 12th floor dumbrock reply:
you see a piece of code probably mean
Java code

for (int j = 0; j et [i] [j] = new EditText (c);
et [i] [j] setTag (R.string.flag, null);.
et [i] [j]. setTag (R.string.colsname, ......

Weak weak to ask your EditText under the two-digit group is how to apply for? How I always null pointer ah?
Reply:
 
/ / Declare
public EditText [] [] et = null;


 
/ / Apply
et = new EditText [rowcount] [colcount];


 
/ / For each application
for (int j = 0; j et [i] [j] = new EditText (c);
}


reference to the 13th floor dlut_labor reply:
reference to the 12th floor dumbrock reply:

You see a piece of code probably mean
Java code

for (int j = 0; j et [i] [j] = new EditText (c);
et [i] [j] setTag (R.string.flag, null);.
et [i] ......

Reply:
The reply was deleted at the moderator 2011-04-13 09:26:32

Reply:
reference to the 7th floor sky123123 reply:
2, you must be an event listener listview is it, this is it, there will be an argument on behalf of you to which item has been clicked, this parameter is the position you want, oh

I tested in listview clickable button edittext and other controls appear after listview's OnItemClickListener event will not work do not know is that right?
Reply:
The reply was deleted at the moderator 2011-04-13 10:26:39

Reply:
On the second question is basically solved EditText array of dynamic applications each set Listener
The first question we have suggested is not?
Elaborate on this issue:
Appears after clicking edittext soft keyboard then click the back button under normal circumstances should you just fill in the characters appear in the soft keyboard disappears edittext but the reality is that after clicking the
edittext is empty
Reply:
Their own roof looking prawns guide!
Reply:
Should not, ah, you do not point to return, points to complete soft keyboard keys above it? I have not encountered such a situation, do you use TextWatcher? Listen to the input of the?
cited 18 floor dlut_labor reply:
On the second question is basically solved EditText array of dynamic applications each set Listener
The first question we have suggested is not?
Elaborate on this issue:
Appears after clicking edittext soft keyboard then click the back button under normal circumstances should be soft keyboard disappears edittext you just fill in the characters appear but the reality is that clicking edittext is empty after the

Reply:
Alas tangle
Reply:
Today, the words encountered the same problem with the landlord, and later even to solve, the code made up, in the hope that in the future to help people
The main idea is to customize an adapter, the adapter found editText on editText add a text change event detection. There will be modified before the event, when modified, the modified parameters, find the desired saved enough.
The above has put you much about it, just simple code code, we hope inspire

class mylistphone {
private TextView tv;
private EditText ed;

}
class myAdapter extends BaseAdapter {
private Context ctx;
private ArrayList al;
private String myend;
private LayoutInflater in;
public myAdapter (Context ctx, ArrayList al) {
this.ctx = ctx;
this.al = al;
}
public int getCount () {
return al.size ();
}

@ Override
public Object getItem (int position) {
return al.get (position);
}

@ Override
public long getItemId (int position) {
return position;
}

@ Override
public View getView (int position, View view, ViewGroup parent) {
/ / String after = "";
/ / Final StringBuffer sb = new StringBuffer ();
mylistphone mylist = new mylistphone ();
in = LayoutInflater.from (ctx);
View v = in.inflate (R.layout.lvphone, null);
mylist.tv = (TextView) v.findViewById (R.id.tvlvphonetype);
mylist.ed = (EditText) v.findViewById (R.id.edlvphonenumber);
mylist.tv.setText (((HashMap) al.get (position)) get ("type") toString ()..);
. String be = ((HashMap) al.get (position)) get ("phonenumber") toString ();.
mylist.ed.setText (((HashMap) al.get (position)) get ("phonenumber") toString ()..);
mylist.ed.addTextChangedListener (new TextWatcher () {
public void onTextChanged (CharSequence s, int start, int before, int count) {
/ / System.out.println ("s:" + s + ", start:" + start + ", before:" + before + ", count:" + count);
}
public void beforeTextChanged (CharSequence s, int start, int count,
int after) {
/ / System.out.println ("s:" + s + ", start:" + start + ", after:" + after + ", count:" + count);
}
public void afterTextChanged (Editable s) {
/ / System.out.println (s.toString ());
/ / Sb.append (s.toString ());
myend = s.toString ();
}
});

if (be.equals (myend) | | myend == null | | myend == "") {
/ / Mylist.ed.setText (myend);
myend = "";
} Else {
/ / System.out.println (myend + ", ttttttttttttttttt");
mylist.ed.setText (myend);
myend = "";
}

return v;
}

}





Reply:
@ Jj5124
I tried the method you said, still does not solve the EditText After editing is complete, click the back button content disappears.
The landlord, your first problem solved yet?

Reply:
And almost ran into the problem of the landlord ListView can not be entered in the EditText get less focus how to do?

No comments:

Post a Comment