Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. public class Texts extends ListActivity
  2. {
  3. String[] data={"How may i help you?", "Please help me", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3"};
  4.  
  5. Drawable[] usrimg=null;
  6. String bgimg = "",_user="",_pass="";
  7. int odd_resID,even_resID;
  8.  
  9. public void onCreate(Bundle savedInstanceState)
  10. {
  11. super.onCreate(savedInstanceState);
  12. System.out.println(" CHAT SCREEN ");
  13.  
  14. //finding the list view
  15. ListView myList = getListView();
  16. myList.setAdapter(new MyCustomAdapter());
  17. myList.setCacheColorHint(0);
  18.  
  19. // setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListContent));
  20. }
  21. class MyCustomAdapter extends BaseAdapter
  22. {
  23.  
  24. /**
  25. * returns the count of elements in the Array that is used to draw the text in rows
  26. * @see android.widget.Adapter#getCount()
  27. */
  28. @Override
  29. public int getCount()
  30. {
  31. return data.length; // data is nothing but the message length
  32. }
  33.  
  34. /**
  35. * Get the data item associated with the specified position in the data set.
  36. * (not Implemented at this point)
  37. * @param position The position of the row that was clicked (0-n)
  38. * @see android.widget.Adapter#getItem(int)
  39. */
  40. @Override
  41. public String getItem(int position)
  42. {
  43. // TODO Auto-generated method stub
  44. return null;
  45. }
  46.  
  47. /**
  48. * Get the row id associated with the specified position in the list.
  49. * (not implemented at this point)
  50. * @param position The position of the row that was clicked (0-n)
  51. * @see android.widget.Adapter#getItemId(int)
  52. */
  53. @Override
  54. public long getItemId(int position)
  55. {
  56. // TODO Auto-generated method stub
  57. return position;
  58. }
  59.  
  60. /**
  61. * Returns the complete row that the System draws.
  62. * It is called every time the System needs to draw a new row;
  63. * You can control the appearance of each row inside this function.
  64. * @param position The position of the row that was clicked (0-n)
  65. * @param convertView The View object of the row that was last created. null if its the first row
  66. * @param parent The ViewGroup object of the parent view
  67. * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
  68. */
  69.  
  70. public View getView(int position, View convertView, ViewGroup parent)
  71. {
  72.  
  73.  
  74. System.out.println("Enter here");
  75.  
  76.  
  77. LayoutInflater inflater = getLayoutInflater();//When you use a custom view in a ListView you must define the row layout.
  78. //You create an xml where you place android widgets and then in the adapter's code
  79. View row;
  80. String even_color,odd_color;
  81.  
  82. // SharedPreferences prefList = getSharedPreferences("PrefsFile",MODE_PRIVATE);
  83. // even_color = prefList.getString("even_bubble_color","pink");
  84. // odd_color = prefList.getString("odd_bubble_color","green");
  85. //
  86. // int even_color_id=getResources().getIdentifier(even_color,"drawable","com.teks.chilltwit"),
  87. // odd_color_id=getResources().getIdentifier(odd_color,"drawable","com.teks.chilltwit");
  88.  
  89.  
  90. //ImageView even_view,odd_view;
  91.  
  92.  
  93. System.out.println("Timeline: Position: "+position+", Length: "+data.length);
  94. // if(position!=data.length-1){
  95.  
  96. if(position%2==0)
  97. {
  98. row = inflater.inflate(R.layout.list_row_layout_even, parent, false);
  99. TextView textLabel = (TextView) row.findViewById(R.id.text);
  100. textLabel.setText(data[position]);
  101.  
  102. }
  103. else
  104. {
  105. row = inflater.inflate(R.layout.list_row_layout_odd, parent, false);
  106. TextView textLabel = (TextView) row.findViewById(R.id.text);
  107. textLabel.setText(data[position]);
  108. }
  109.  
  110. return (row);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement