0

I am a novice programmer, I wrote some code. I want get wallet_id in another class, but when I try this variable always have value = 0. In class ChooseWallet wallet_id sets value wallet_id well. But I don't know how get wallet_id in another class. Any idea?

public class ChooseWallet extends AppCompatActivity {
public int wallet_id;
DatabaseDEO db = new DatabaseDEO(this);
ListView choose;
private SimpleCursorAdapter adapter;
final String[] from = new String[] {Wallets.COLUMNS.name,Wallets.COLUMNS.surname};
final int[] to = new int[] {R.id.name, R.id.surname };



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose_wallet);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    choose = (ListView)findViewById(R.id.listselement);
    choose.setEmptyView(findViewById(R.id.null));
    Cursor cursor = db.fetch();
    adapter = new SimpleCursorAdapter(this, R.layout.activity_see_record, cursor, from, to, 0);
    adapter.notifyDataSetChanged();

    choose.setAdapter(adapter);

        choose.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        walllet_id = position+1;
    }
});

}}

Adrien
  • 11
  • 5
  • Possible duplicate of [How to get id of particular item of listview in android?](http://stackoverflow.com/questions/27103754/how-to-get-id-of-particular-item-of-listview-in-android) – Lincoln Bergeson Dec 12 '16 at 22:09
  • This isn't a duplication. I want get selectem item id and use this id in other class. At this point, ID = 0 shall always, because after declaring a variable it has a value of 0. – Adrien Dec 13 '16 at 00:36
  • Can you whittle down your question to something more identifiable? – Lincoln Bergeson Dec 13 '16 at 04:07
  • Ok. I try but my English was never too good. – Adrien Dec 13 '16 at 09:28

2 Answers2

0

In my opinion this is impossible. Spinner was better solutions than ListView.

Martin
  • 3
  • 4
0

maybe you can try to use setOnItemClickListener . like this:

    choose.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            walllet_id = position+1;
        }
    });
NateZh
  • 81
  • 1
  • 3
  • I correct it, but still when I try use variable in another class wallet_id have value = 0. In class ChooseWallet have a good value, but I don't know how get wallet_id in another class. – Adrien Dec 13 '16 at 09:22