Building a list with edittext
I have a listview and its lines contain edittext. And the length of the listview is 7. When you enter a value on the first line, it is also inserted on the 7th line. I have been stuck with this issue for the last 2 days. Please help me. `Package
com.teacherapp.adapter;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.koushikdutta.urlimageviewhelper.UrlImageViewCallback;
import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import com.mikhaellopez.circularimageview.CircularImageView;
import com.teacherapp.async.GetMarksAsync;
import com.teacherapp.bean.TeacherBean;
import com.teacherapp.fragments.MarkeUpdateFragment;
import com.teacherapp.utility.ConstantTeacher;
import com.wemited.schoolfly.teacherapp.R;
public class MarksListAdaptor extends BaseAdapter {
List<TeacherBean> recentitems;
LayoutInflater inflate;
TeacherBean item;
AlertDialog alertDialog, fpDialog;
public static final String KEY_SETTING = "setting";
public static CheckBox check_img;
Context context;
@SuppressWarnings("unused")
private boolean isChecking = true;
@SuppressWarnings("unused")
private int mCheckedId = R.id.type1;
public static String status_all;
int position1;
//String marks;
public MarksListAdaptor(Activity context, List<TeacherBean> recentitems,
String string) {
this.recentitems = recentitems;
inflate = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
status_all = string;
}
@Override
public int getCount() {
return recentitems.size();
}
@Override
public Object getItem(int position) {
return recentitems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView txt_name, txt_father;
public CircularImageView logo_img;
public EditText edt_marks, edt_grad;
}
@SuppressLint("InflateParams")
@SuppressWarnings("unused")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
item = recentitems.get(position);
final TeacherBean item1 = (TeacherBean) getItem(position);
View myview = convertView;
if (convertView == null) {
myview = inflate.inflate(R.layout.stud_mark_list_item, null);
}
final ViewHolder holder = new ViewHolder();
holder.txt_name = (TextView) myview.findViewById(R.id.txt_name);
holder.txt_father = (TextView) myview.findViewById(R.id.txt_father);
holder.logo_img = (CircularImageView) myview.findViewById(R.id.img);
holder.edt_marks = (EditText) myview.findViewById(R.id.edt_marks);
holder.edt_grad = (EditText) myview.findViewById(R.id.edt_grad);
holder.txt_name.setText("" + item.getStudent_name());
holder.txt_father.setText("" + item.getStudent_roll_no());
if (status_all.equals("0")) {
holder.edt_marks.setVisibility(View.INVISIBLE);
holder.edt_grad.setVisibility(View.VISIBLE);
} else {
holder.edt_grad.setVisibility(View.INVISIBLE);
holder.edt_marks.setVisibility(View.VISIBLE);
}
String logo = ConstantTeacher.img_base + item.getStudent_img();
holder.logo_img.setAnimation(null);
UrlImageViewHelper.setUrlDrawable(holder.logo_img, logo,
R.drawable.ic_launcher, new UrlImageViewCallback() {
@Override
public void onLoaded(ImageView imageView,
Bitmap loadedBitmap, String url,
boolean loadedFromCache) {
if (!loadedFromCache) {
}
}
});
holder.edt_marks.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
String marks = holder.edt_marks.getText().toString();
GetMarksAsync.status_list.set(position, marks);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.edt_grad.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
String grad = holder.edt_grad.getText().toString();
System.out.println("marks"+grad);
GetMarksAsync.status_list.set(position, grad);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
return myview;
}
}
This is my XML layout -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.wemited.teacherapp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="5dp"
android:background="@drawable/layout_box_corners_blue"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".23"
android:orientation="vertical" >
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/img"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:scaleType="centerCrop"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight=".52"
android:orientation="vertical" >
<TextView
android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/app_theme_color"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txt_father"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text=""
android:textColor="@color/app_green"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".25" >
<EditText
android:id="@+id/edt_marks"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="@drawable/layout_box_corners_blue"
android:gravity="center"
android:hint=""
android:inputType="numberDecimal"
android:maxLength="5"
android:padding="2dp"
android:singleLine="true"
android:textColor="@color/app_theme_color"
android:textColorHint="@color/GrayLight"
android:textCursorDrawable="@null"
android:textSize="13dp" />
<EditText
android:id="@+id/edt_grad"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/edt_marks"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="@drawable/layout_box_corners_blue"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
android:gravity="center"
android:hint=""
android:inputType="numberDecimal"
android:maxLength="3"
android:padding="2dp"
android:singleLine="true"
android:textColor="@color/app_theme_color"
android:textColorHint="@color/GrayLight"
android:textCursorDrawable="@null"
android:textSize="13dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
+3
source to share
No one has answered this question yet
Check out similar questions: