Guest User

Untitled

a guest
Dec 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. import android.app.Activity;
  4. import android.app.ListActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.AdapterView;
  11. import android.widget.AdapterView.OnItemClickListener;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.Button;
  14. import android.widget.LinearLayout;
  15. import android.widget.ListView;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. public class RateListDemo extends ListActivity implements OnItemClickListener{
  20. TextView selection;
  21. String[] items={"lorem", "ipsum", "dolor", "sit", "amet",
  22. "consectetuer", "adipiscing", "elit", "morbi", "vel",
  23. "ligula", "vitae", "arcu", "aliquet", "mollis",
  24. "etiam", "vel", "erat", "placerat", "ante",
  25. "porttitor", "sodales", "pellentesque", "augue",
  26. "purus"};
  27.  
  28. @Override
  29. public void onCreate(Bundle icicle) {
  30. super.onCreate(icicle);
  31. setContentView(R.layout.main);
  32.  
  33. ArrayList<RowModel> list=new ArrayList<RowModel>();
  34.  
  35. for (String s : items) {
  36. list.add(new RowModel(s));
  37. }
  38. ListView nit=getListView();
  39. setListAdapter(new CheckAdapter(this, list));
  40. selection=(TextView)findViewById(R.id.selection);
  41. nit.setOnItemClickListener(this);
  42.  
  43.  
  44. }
  45.  
  46. private RowModel getModel(int position) {
  47. return(((CheckAdapter)getListAdapter()).getItem(position));
  48. }
  49.  
  50. public void onListItemClick(ListView parent, View v,
  51. int position, long id) {
  52. selection.setText(getModel(position).toString());
  53. }
  54.  
  55. class CheckAdapter extends ArrayAdapter<RowModel> {
  56. Activity context;
  57.  
  58. CheckAdapter(Activity context, ArrayList<RowModel> list) {
  59. super(context, R.layout.row, list);
  60.  
  61. this.context=context;
  62. }
  63.  
  64. public View getView(int position, View convertView,
  65. ViewGroup parent) {
  66. View row=convertView;
  67. ViewWrapper wrapper;
  68. final Button but;
  69.  
  70. if (row==null) {
  71. LayoutInflater inflater=context.getLayoutInflater();
  72.  
  73. row=inflater.inflate(R.layout.row, null);
  74. wrapper=new ViewWrapper(row);
  75. row.setTag(wrapper);
  76. but=wrapper.getRatingBar();
  77. }
  78. else {
  79. wrapper=(ViewWrapper)row.getTag();
  80. but=wrapper.getRatingBar();
  81. }
  82.  
  83. RowModel model=getModel(position);
  84.  
  85. wrapper.getLabel().setText(model.toString());
  86. but.setTag(new Integer(position));
  87. but.setVisibility(4);
  88. but.setOnClickListener(new View.OnClickListener() {
  89.  
  90. public void onClick(View v) {
  91. Integer myPosition=(Integer)v.getTag();
  92. RowModel model=getModel(myPosition);
  93. Toast.makeText(context, model.label, Toast.LENGTH_SHORT).show();
  94.  
  95. if(model.label=="purus"){
  96. Toast.makeText(context, "Hi this is sit", Toast.LENGTH_SHORT).show();
  97. finish();
  98.  
  99. }
  100. LinearLayout parent=(LinearLayout)v.getParent();
  101. TextView label=(TextView)parent.findViewById(R.id.label);
  102.  
  103. label.setText(model.toString());
  104. }
  105. });
  106.  
  107.  
  108. return(row);
  109. }
  110. }
  111.  
  112. class RowModel {
  113. String label;
  114. float rating=2.0f;
  115.  
  116. RowModel(String label) {
  117. this.label=label;
  118. }
  119.  
  120. public String toString() {
  121. if (rating>=3.0) {
  122. return(label.toUpperCase());
  123. }
  124.  
  125. return(label);
  126. }
  127. }
  128.  
  129. @Override
  130. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  131. // TODO Auto-generated method stub
  132. LayoutInflater inflater=((Activity) getApplicationContext()).getLayoutInflater();
  133. Log.e("ntin", "working");
  134. inflater.inflate(R.layout.row, null);
  135.  
  136. Button but=(Button)findViewById(R.id.button1);
  137. but.setVisibility(0);
  138.  
  139. }
  140. }
Add Comment
Please, Sign In to add comment