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

51
LINES

< > BotCompany Repo | #1004466 // Android ListView Demo II (with strings, onClick, works)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (321L/3K/10K).

1  
!752
2  
3  
import android.view.*;
4  
import android.widget.*;
5  
import android.content.*;
6  
7  
p {androidUI(r {
8  
    ListView lv = new ListView(androidActivity());
9  
lv.setAdapter(new MyAdapter(androidActivity (), new S[] {"a", "b", "c", "d"}));
10  
11  
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
12  
13  
        @Override
14  
        public void onItemClick(AdapterView<?> arg0, View arg1,
15  
                int position, long id) {
16  
  androidShowText (str(position));
17  
  }
18  
});
19  
20  
21  
  androidShow (lv);
22  
  });
23  
}
24  
25  
     
26  
27  
    sclass 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  
    }

Author comment

Began life as a copy of #1004464

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004466
Snippet name: Android ListView Demo II (with strings, onClick, works)
Eternal ID of this version: #1004466/1
Text MD5: 4d6e8839f2029ed9a755e6b68a1e97c4
Transpilation MD5: b5129f799ed739c8c4ea6c2706711f18
Author: stefan
Category: javax / eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-05 06:32:04
Source code size: 1403 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 563 / 582
Referenced in: [show references]