I've got table with 2 Colums: GOAL(text) and FLAG(0 or 1) If value from FLAG = 1 text from GOAL get Strike.
final TextView txt=null;
scAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.tvText ){
if (cursor.getInt(cursor.getColumnIndex(DB.COLUMN_FLAG)) ==1 ){
String goal = cursor.getString(cursor.getColumnIndex(DB.COLUMN_GOAL));
txt.setText(goal);
txt.setPaintFlags(txt.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
}
return false;
}
});
Quite simple code, but problem with converting from String to Text.
I see 2 ways: strike sring value or fix this problem.
Maybe there is another way...
Help, please!
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): FATAL EXCEPTION: main
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): **java.lang.NullPointerException**
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at com.example.dayplan.mar2014$2.setViewValue(mar2014.java:108)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:126)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.CursorAdapter.getView(CursorAdapter.java:186)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.ListView.makeAndAddView(ListView.java:1745)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.ListView.fillDown(ListView.java:670)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.ListView.fillFromTop(ListView.java:727)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.ListView.layoutChildren(ListView.java:1598)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.View.layout(View.java:7175)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.View.layout(View.java:7175)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.View.layout(View.java:7175)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.View.layout(View.java:7175)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.View.layout(View.java:7175)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.ViewRoot.performTraversals(ViewRoot.java:1142)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.os.Looper.loop(Looper.java:130)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at android.app.ActivityThread.main(ActivityThread.java:3822)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at java.lang.reflect.Method.invoke(Method.java:507)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-25 19:03:17.410: ERROR/AndroidRuntime(14935): at dalvik.system.NativeStart.main(Native Method)
You need assign the tvText TextView
to txt
final TextView txt=null;
scAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.tvText ){
//add this line
txt = (TextView)view;
if (cursor.getInt(cursor.getColumnIndex(DB.COLUMN_FLAG)) ==1 ){
String goal = cursor.getString(cursor.getColumnIndex(DB.COLUMN_GOAL));
txt.setText(goal);
txt.setPaintFlags(txt.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
else txt.setPaintFlags(txt.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}
return false;
}
});