Android: jeden identyfikator przycisku, wiele przycisków, jeden identyfikator widoku, użycie getTag (), setTag ()

Jestem w stanie wyświetlić całą lub selektywną liczbę rekordów za pomocą getAllRecords () i getRecord (long id). Chodzi o to, że chcę wyświetlić inny rekord dla każdego przycisku widoku na mojej rozwijalnej liście child.each dziecko ma dołączony przycisk widoku. Pozycja grupy jest znana (pierwsza grupa). ale pozycja dziecka wydaje się niemożliwa do wyśledzenia. Mam tylko jeden identyfikator zasobu. jak mam wtedy wyświetlać różne rekordy dla każdego dziecka? proszę o pomoc, ponieważ wprowadza to w błąd. Oto kod MyCustomAdapter.java, kod Parent.java i kod DisplayCursor.java. próbowałem wymyślić, jak znaleźć sposób na wyodrębnienie identyfikatora dziecka i wyodrębnić ten konkretny rekord z id.but wszystko na próżno. UPDATE: okazało się, że muszę użyć getTag () i viewTag (), aby to się stało. Ale nie znajduję żadnego zasobu w sieci, aby poprawnie pokazać mi, jak to zrobić w tym przypadku.

Kod MyCustomAdapter. (zawiera rozszerzalne funkcje listy getchildview i getgroupview)

public class MyCustomAdapter extends BaseExpandableListAdapter {


private LayoutInflater inflater;
private ArrayList<parent> mParent;
public MyCustomAdapter(){}
public MyCustomAdapter(Context context, ArrayList<parent> parent){
    mParent = parent;
    inflater = LayoutInflater.from(context);
}


@Override
//counts the number of group/parent items so the list knows how many times calls getGroupView() method
public int getGroupCount() {
    return mParent.size();
}

@Override
//counts the number of children items so the list knows how many times calls getChildView() method
public int getChildrenCount(int i) {
    return mParent.get(i).getArrayChildren().size();
}

@Override
//gets the title of each parent/group
public Object getGroup(int i) {
    return mParent.get(i).getTitle();
}

@Override
//gets the name of each item
public Object getChild(int i, int i1) {
    return mParent.get(i).getArrayChildren().get(i1);
}

@Override
public long getGroupId(int i) {
    return i;
}

@Override
public long getChildId(int i, int i1) {
    return i1;
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
//in this method you must set the text to see the parent/group on the list
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {

    if (view == null) {
        view = inflater.inflate(R.layout.investment_summary_parent, viewGroup,false);
    }

    TextView textView = (TextView) view.findViewById(R.id.list_item_text_view);
    //"i" is the position of the parent/group in the list
    textView.setText(getGroup(i).toString());

    //return the entire view
    return view;
}

@Override
//in this method you must set the text to see the children on the list
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
    if (view == null) {
        view = inflater.inflate(R.layout.investment_summary_child, viewGroup,false);

    }
   // viewbutton.getTag();
    TextView textView = (TextView) view.findViewById(R.id.list_item_text_child);
    //"i" is the position of the parent/group in the list and 
    //"i1" is the position of the child
    textView.setText(mParent.get(i).getArrayChildren().get(i1));

    //return the entire view
    return view;
}

@Override
public boolean isChildSelectable(int i, int i1) {
    return true;
}

@Override
public void registerDataSetObserver(DataSetObserver observer) {
    /* used to make the notifyDataSetChanged() method work */
    super.registerDataSetObserver(observer);
}
}

Kod nadrzędny (rozwijane metody nadrzędne)

public class parent {
private String mTitle;
private ArrayList<String> mArrayChildren;

public String getTitle() {
    return mTitle;
}

public void setTitle(String mTitle) {
    this.mTitle = mTitle;
}

public ArrayList<String> getArrayChildren() {
    return mArrayChildren;
}

public void setArrayChildren(ArrayList<String> mArrayChildren) {
    this.mArrayChildren = mArrayChildren;
}
}

Kod DisplayCursor: klasa publiczna DisplayCursor extends ListActivity {DBAdapter db = new DBAdapter (this);

@Override
public void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_cursor);
filldata();

}
@SuppressWarnings("deprecation")
public void filldata(){
db.open();

Cursor cursor = db.getRecord(2);//displays 2nd record
startManagingCursor(cursor);

String[] columns = new String[] {DBAdapter.invest_type,DBAdapter.curr_per_share_price, DBAdapter.share_name,
        DBAdapter.no_of_shares,DBAdapter.share_identity,DBAdapter.purchase_price,
        DBAdapter.purchase_from,DBAdapter.purchase_date,DBAdapter.purchase_contact};

int[] to = new int[] { R.id.investmenttype,R.id.currpershareprice,R.id.sharename,R.id.shareno,R.id.shareid,    R.id.purprice,
        R.id.purfrom,R.id.purdate,R.id.purcon};
 SimpleCursorAdapter mAdapter = new SimpleCursorAdapter( this, R.layout.row, cursor, columns, to);
 this.setListAdapter(mAdapter);
 db.close();

 }   
 }

PROSZĘ skierować mnie do tego, jakie zmiany muszę wprowadzić, aby wyświetlić inny rekord dla każdego przycisku widoku. Oznacza to, że po kliknięciu pierwszego przycisku widoku dziecka musi zostać wyświetlony pierwszy rekord, kliknięty zostanie przycisk widoku drugiego dziecka, co oznacza, że ​​musi zostać wyświetlony drugi rekord. tak więc powiedzmy, że mam 3 dzieci, 3 odpowiednie przyciski widoku i 3 rekordy.

questionAnswers(0)

yourAnswerToTheQuestion