Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1005315 // AndroidList - Android ListView with strings

JavaX fragment (include)

1  
import android.view.*;
2  
import android.widget.*;
3  
import android.content.*;
4  
5  
sclass AndroidList {
6  
  ListView lv;
7  
  O onClick;
8  
9  
  View view() { ret lv; }
10  
11  
  *(L<S> l) {
12  
    lv = new ListView(androidActivity());
13  
    lv.setAdapter(new MyAdapter(androidActivity (), toStringArray(l)));
14  
15  
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
16  
17  
        @Override
18  
        public void onItemClick(AdapterView<?> arg0, View arg1,
19  
                int position, long id) {
20  
 callF(onClick, position);
21  
  }
22  
});
23  
}
24  
25  
     
26  
27  
    class MyAdapter extends ArrayAdapter<String> {
28  
29  
        public MyAdapter(Context context, String[] strings) {
30  
            super(context, -1, -1, strings);
31  
        }
32  
33  
        @Override
34  
        public View getView(int position, View convertView, ViewGroup parent) {
35  
36  
            LinearLayout listLayout = new LinearLayout(getContext ());
37  
            listLayout.setLayoutParams(new AbsListView.LayoutParams(
38  
                    AbsListView.LayoutParams.FILL_PARENT,                
39  
                    AbsListView.LayoutParams.WRAP_CONTENT));
40  
            listLayout.setId(View.generateViewId());
41  
42  
            TextView listText = new TextView(getContext());
43  
            listText.setId(View.generateViewId());
44  
45  
            listLayout.addView(listText);
46  
47  
        listText.setText(super.getItem(position));
48  
49  
            return listLayout;
50  
        }
51  
    }
52  
}

Author comment

Began life as a copy of #1004466

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005315
Snippet name: AndroidList - Android ListView with strings
Eternal ID of this version: #1005315/2
Text MD5: 9eb5b1865c79a9221bd9d15547a4a85e
Author: stefan
Category: javax / android
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-19 12:27:35
Source code size: 1420 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 505 / 1073
Version history: 1 change(s)
Referenced in: [show references]