Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. public class MainActivity extends Activity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7. ArrayList<HashMap<String, String>>val1=new ArrayList<HashMap<String,String>>();
  8. HashMap<String, String>val=new HashMap<String,String>();
  9. val.put("a","a");
  10. val.put("c","c");
  11. val.put("b","b");
  12. val1.add(val);
  13.  
  14. final ListView l=(ListView)findViewById(R.id.listView1);
  15. ListAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"TaskId","heading","status"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus});
  16.  
  17. Button b=(Button)findViewById(R.id.mytask);
  18. b.setOnClickListener(new OnClickListener() {
  19.  
  20. @Override
  21. public void onClick(View arg0) {
  22. // TODO Auto-generated method stub
  23. Toast.makeText(MainActivity.this,"save",Toast.LENGTH_SHORT).show();
  24. }
  25. });
  26. l.setAdapter(k);
  27.  
  28.  
  29.  
  30.  
  31. }
  32.  
  33. 04-07 01:43:07.075: E/AndroidRuntime(2113): FATAL EXCEPTION: main
  34. 04-07 01:43:07.075: E/AndroidRuntime(2113): Process: com.example.s, PID: 2113
  35. 04-07 01:43:07.075: E/AndroidRuntime(2113): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.s/com.example.s.MainActivity}: java.lang.NullPointerException
  36. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  37. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  38. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread.access$800(ActivityThread.java:135)
  39. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  40. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.os.Handler.dispatchMessage(Handler.java:102)
  41. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.os.Looper.loop(Looper.java:136)
  42. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread.main(ActivityThread.java:5017)
  43. 04-07 01:43:07.075: E/AndroidRuntime(2113): at java.lang.reflect.Method.invokeNative(Native Method)
  44. 04-07 01:43:07.075: E/AndroidRuntime(2113): at java.lang.reflect.Method.invoke(Method.java:515)
  45. 04-07 01:43:07.075: E/AndroidRuntime(2113): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  46. 04-07 01:43:07.075: E/AndroidRuntime(2113): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  47. 04-07 01:43:07.075: E/AndroidRuntime(2113): at dalvik.system.NativeStart.main(Native Method)
  48. 04-07 01:43:07.075: E/AndroidRuntime(2113): Caused by: java.lang.NullPointerException
  49. 04-07 01:43:07.075: E/AndroidRuntime(2113): at com.example.s.MainActivity.onCreate(MainActivity.java:34)
  50. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.Activity.performCreate(Activity.java:5231)
  51. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  52. 04-07 01:43:07.075: E/AndroidRuntime(2113): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  53. 04-07 01:43:07.075: E/AndroidRuntime(2113): ... 11 more
  54.  
  55. <?xml version="1.0" encoding="utf-8"?>
  56. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  57. android:layout_width="match_parent"
  58. android:layout_height="match_parent"
  59. android:orientation="vertical"
  60.  
  61. >
  62.  
  63. <TextView
  64. android:id="@+id/textView1"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:layout_alignParentLeft="true"
  68. android:layout_alignParentTop="true"
  69. android:layout_marginTop="18dp"
  70. android:text="Task Name:"
  71.  
  72. android:textSize="15dp"
  73. android:textStyle="bold" />
  74.  
  75. <TextView
  76. android:id="@+id/View1"
  77. android:layout_width="wrap_content"
  78. android:layout_height="wrap_content"
  79. android:layout_alignParentLeft="true"
  80. android:layout_alignParentTop="true"
  81. android:text="TextView"
  82.  
  83. android:textSize="15dp"
  84. android:textStyle="bold"
  85. android:visibility="invisible" />
  86.  
  87. <TextView
  88. android:id="@+id/View2"
  89. android:layout_width="wrap_content"
  90. android:layout_height="wrap_content"
  91. android:layout_alignBaseline="@+id/textView1"
  92. android:layout_alignBottom="@+id/textView1"
  93. android:layout_marginLeft="31dp"
  94. android:layout_toRightOf="@+id/textView1"
  95. android:text="TextView"
  96.  
  97. android:textSize="15dp"
  98. android:textStyle="bold"
  99. android:visibility="visible" />
  100.  
  101. <TextView
  102. android:id="@+id/ViewStatus"
  103. android:layout_width="wrap_content"
  104. android:layout_height="wrap_content"
  105. android:layout_alignBaseline="@+id/View2"
  106. android:layout_alignBottom="@+id/View2"
  107. android:layout_alignParentRight="true"
  108. android:text="Pending"
  109.  
  110. android:textSize="15dp"
  111. android:textStyle="bold" />
  112.  
  113. <TextView
  114. android:id="@+id/textView2"
  115. android:layout_width="wrap_content"
  116. android:layout_height="wrap_content"
  117. android:layout_alignBaseline="@+id/ViewStatus"
  118. android:layout_alignBottom="@+id/ViewStatus"
  119. android:layout_marginRight="14dp"
  120. android:layout_toLeftOf="@+id/ViewStatus"
  121. android:text="Status:"
  122.  
  123. android:textSize="15dp"
  124. android:textStyle="bold" />
  125.  
  126. <Button
  127. android:id="@+id/mytask"
  128. android:layout_width="wrap_content"
  129. android:layout_height="wrap_content"
  130. android:layout_alignParentLeft="true"
  131. android:layout_below="@+id/textView1"
  132. android:text="Button" />
  133.  
  134. </RelativeLayout>
  135.  
  136. <ListView
  137. android:id="@+id/listView1"
  138. android:layout_width="match_parent"
  139. android:layout_height="wrap_content"
  140. android:layout_alignParentLeft="true"
  141. android:layout_alignParentTop="true"
  142. android:layout_marginLeft="106dp"
  143. android:layout_marginTop="124dp" >
  144. </ListView>
  145.  
  146. SimpleAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"a","c","b"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus})
  147. {
  148. @Override
  149. public View getView (int position, View convertView, ViewGroup parent)
  150. {
  151. View v = super.getView(position, convertView, parent);
  152.  
  153. Button b=(Button)v.findViewById(R.id.mytask);
  154. b.setOnClickListener(new OnClickListener() {
  155.  
  156. @Override
  157. public void onClick(View arg0) {
  158. // TODO Auto-generated method stub
  159. Toast.makeText(MainActivity.this,"save",Toast.LENGTH_SHORT).show();
  160. }
  161. });
  162. return v;
  163. }
  164.  
  165.  
  166. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement