InSide ListView : android:descendantFocusability="beforeDescendants"
row 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="wrap_content"
android:background="@color/white"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/row_renew_tran_txtSSCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="SS Code"
android:textColor="@color/black"
android:textSize="22sp" />
<ImageView
android:layout_width="0.5px"
android:layout_height="fill_parent"
android:background="@color/blue" />
<TextView
android:id="@+id/row_renew_tran_txtUID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="uID"
android:textColor="@color/blue"
android:textSize="17sp" />
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="0.5px"
android:background="@color/blue" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/row_renew_tran_txtInstAmt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Inst Amt."
android:textColor="@color/blue"
android:textSize="17sp" />
<ImageView
android:layout_width="0.5px"
android:layout_height="fill_parent"
android:background="@color/blue" />
<TextView
android:id="@+id/row_renew_tran_txtDueAmt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Due Amt."
android:textColor="@color/blue"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="1px"
android:layout_height="fill_parent"
android:background="@color/blue" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2.5"
android:orientation="vertical" >
<EditText
android:id="@+id/row_renew_tran_edtTranAmt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/editbox_background_normal"
android:gravity="right|center_vertical"
android:imeOptions="actionNext"
android:inputType="number"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="22sp" />
</LinearLayout>
</LinearLayout>
In Adapter :
final ViewHolder holder;
View rowView = convertView;
if (rowView == null) {
holder = new ViewHolder();
rowView = inflater.inflate(R.layout.row_renew_tran, null);
holder.txtSSCode = (TextView) rowView.findViewById(R.id.row_renew_tran_txtSSCode);
holder.txtUID = (TextView) rowView.findViewById(R.id.row_renew_tran_txtUID);
holder.txtInstAmt = (TextView) rowView.findViewById(R.id.row_renew_tran_txtInstAmt);
holder.txtDueAmt= (TextView) rowView.findViewById(R.id.row_renew_tran_txtDueAmt);
holder.edtTranAmt = (EditText) rowView.findViewById(R.id.row_renew_tran_edtTranAmt);
holder.txtSSCode.setTag(position);
holder.edtTranAmt.setTag(holder.edtTranAmt);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
final ReNewTranModel model = arrayList.get(position);
try {
holder.txtSSCode.setText(model.getSSCode());
holder.txtUID.setText(String.valueOf(model.getUID()));
holder.txtInstAmt.setText(String.valueOf(model.getInstAmt()));
holder.txtDueAmt.setText(String.valueOf(model.getDueAmt()));
if(model.getTranAmt() > 0)
holder.edtTranAmt.setText(String.valueOf(model.getTranAmt()));
else
holder.edtTranAmt.setText("");
} catch (Exception e) {
e.printStackTrace();
}
int tag_position=(Integer) holder.txtSSCode.getTag();
holder.txtSSCode.setId(tag_position);
holder.edtTranAmt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
final int position2 = holder.txtSSCode.getId();
final EditText Caption = (EditText) holder.edtTranAmt;
if(Caption.getText().toString().length()>0){
arrayList.get(position2).setTranAmt(Integer.valueOf(Caption.getText().toString()));
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.edtTranAmt.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT
&& position != arrayList.size() - 1) {
final EditText Caption = (EditText) holder.edtTranAmt.getTag();
Caption.postDelayed(new Runnable() {
public void run() {
EditText nextField = (EditText)Caption.focusSearch(View.FOCUS_DOWN);
if(nextField != null) {
nextField.requestFocus();
}
}
}, 200);
return false;
}else if (actionId == EditorInfo.IME_ACTION_NEXT &&
(position == arrayList.size() - 1) ) {
mUpdateTotalValue.onUpdateResult();
InputMethodManager imm =
(InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.edtTranAmt.getWindowToken(), 0);
return false;
}else if (actionId == EditorInfo.IME_ACTION_DONE ) {
return false;
}
return false;
/*if (actionId == EditorInfo.IME_ACTION_NEXT ) {
try {
model.setTranAmt(Integer.valueOf(holder.edtTranAmt.getText().toString()));
notifyDataSetChanged();
mUpdateTotalValue.onUpdateTotal(position, Integer.valueOf(holder.edtTranAmt.getText().toString()));
} catch (NumberFormatException e) {
e.printStackTrace();
}
holder.edtTranAmt.clearFocus();
holder.edtTranAmt.requestFocus();
return true;
}
return false;*/
}
});
/*holder.edtTranAmt.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
Log.e("", "onFocusChange "+hasFocus+ " name " +model.getSSCode());
if (!hasFocus){
// final int position = v.getId();
final EditText caption = (EditText) v;
holder.edtTranAmt.setText(caption.getText().toString());
try {
if(caption.getText().toString().trim().length() >0){
model.setTranAmt(Integer.valueOf(caption.getText().toString()));
notifyDataSetChanged();
mUpdateTotalValue.onUpdateTotal(position, Integer.valueOf(holder.edtTranAmt.getText().toString()));
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
});*/
return rowView;
No comments:
Post a Comment