Rating ActivityEnvoi valeur des lignes à WebService au format JSON (Android)
Tâche: application reçoit des valeurs au format JSON et Nom de l'élève et note actuelle sont dynamiquement à la Liste. Maintenant, l'application doit envoyer une note et des commentaires pour chaque étudiant au format JSON. Problème: Les valeurs indiquées dans Notation et commentaire peuvent être récupérées dans la classe Adapter (où une seule ligne est remplie) mais ne sont pas accessibles en dehors de cette classe. Je veux accéder à ces valeurs dans la méthode ListView.onClickListener.
Cette classe est Adaptateur:
class StudentAdapter extends BaseAdapter {
ArrayList<Student> studentList;
ArrayList<Student> studentList1;
LayoutInflater inflater;
public StudentAdapter(ArrayList<Student> studentList) {
this.studentList = studentList;
inflater = LayoutInflater.from(RatingActivity.this);
}
@Override
public int getCount() {
return studentList.size();
}
@Override
public Object getItem(int position) {
return studentList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final View row = inflater.inflate(R.layout.rowactivity3, parent, false);
// TextView id = (TextView) row.findViewById(R.id.tvId);
TextView name = (TextView) row.findViewById(R.id.tvName);
final RatingBar rv=(RatingBar)row.findViewById(R.id.ratingBar);
final RatingBar rv1=(RatingBar)row.findViewById(R.id.ratingBar1);
final Button b1=(Button)row.findViewById(R.id.btnDialog);
final String[] values = {null,null};
name.setText(studentList.get(position).getSname());
rv1.setRating(studentList.get(position).getRate());
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(RatingActivity.this);
builder.setTitle("Comment here:");
final EditText input = new EditText(RatingActivity.this);
input.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_CLASS_TEXT);
builder.setView(input);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_Text = input.getText().toString();
Log.d("comment",m_Text);
values[0]=m_Text;
b1.setBackgroundColor(Color.BLUE);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
});
return row;
}
}
Ceci est la mise en page de la ligne unique:
<TextView
android:layout_margin="8dp"
android:id="@+id/tvName"
android:text="enter name.."
android:padding="12dp"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
<RatingBar
android:id="@+id/ratingBar"
style="@style/customRatingBar"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:numStars="5"
android:stepSize="0.1" />
<Button
android:id="@+id/btnDialog"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:text="Click"/>
<RatingBar
android:id="@+id/ratingBar1"
android:layout_marginLeft="80dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:isIndicator="true"
android:stepSize="0.1" />
Vous pouvez essayer ListView.setOnItemClickListener –
J'ai essayé cela, il ne fonctionne pas lorsque la barre d'évaluation et les boutons sont présents dans la rangée. – user5166776