I have four imageviews which are set to invisible at activity start (or rather at row inflation). I would like to press a button and have them ALL become visible (and subsequently be operational as onclicks...). I have the following summary code, but I keep getting errors whenever I try to access any other imageview other than the last one.
public class xx {
private ImageView up;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Log.i(TAG, "excersizeAdapter getView");
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Excersize e = items.get(position);
if (e != null) {
TextView exTitle = (TextView) v.findViewById(R.id.ex_type_title);
TextView exOn = (TextView) v.findViewById(R.id.ex_on_title);
TextView exRestAmount = (TextView) v.findViewById(R.id.ex_rest_amount);
TextView exSequence = (TextView) v.findViewById(R.id.ex_sequence);
up = (ImageView) v.findViewById(R.id.moveup);
down = (ImageView) v.findViewById(R.id.movedown);
if (exTitle !=null) {
exTitle.setText(e.getTypeTitle());
}
if (exOn !=null) {
exOn.setText("On: "+e.getTypeOn());
}
if (exRestAmount !=null) {
exRestAmount.setText(e.getRestAmount().toString());
}
if (exSequence !=null) {
exSequence.setText(e.getSequence().toString());
up.setTag(8881);
down.setTag(8882);
up.setId(((Integer)e.getSequence()));
down.setId(((Integer)e.getSequence()));
Log.i(TAG, "up,down values=" +e.getSequence());
}
}
return v;
}
}
public void toggleReorderButtons() {
up.findViewById(2).setVisibility(View.VISIBLE);
up.setVisibility(View.VISIBLE);
up.setOnClickListener(this);
}
}
OK, this is cut down code, but in the makevisinvis method up.findview...
it causes a crash and up.setvis, etc. will turn on only the last one that was added to my activity.
I also tried the following with no success.
ImageView upper = (ImageView) up.findViewById(2);
upper.setVisibility(View.VISIBLE);
A lovely error dump:
04-21 09:10:55.650: W/dalvikvm(22392): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
04-21 09:10:55.675: E/AndroidRuntime(22392): FATAL EXCEPTION: main
04-21 09:10:55.675: E/AndroidRuntime(22392): java.lang.NullPointerException
04-21 09:10:55.675: E/AndroidRuntime(22392): at com.mediabarltd.digittrainer.ProgramDisplay.toggleReorderButtons(ProgramDisplay.java:437)
04-21 09:10:55.675: E/AndroidRuntime(22392): at com.mediabarltd.digittrainer.ProgramDisplay.onClick(ProgramDisplay.java:391)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.view.View.performClick(View.java:2538)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.view.View$PerformClick.run(View.java:9152)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.os.Handler.handleCallback(Handler.java:587)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.os.Handler.dispatchMessage(Handler.java:92)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.os.Looper.loop(Looper.java:130)
04-21 09:10:55.675: E/AndroidRuntime(22392): at android.app.ActivityThread.main(ActivityThread.java:3691)
04-21 09:10:55.675: E/AndroidRuntime(22392): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 09:10:55.675: E/AndroidRuntime(22392): at java.lang.reflect.Method.invoke(Method.java:507)
04-21 09:10:55.675: E/AndroidRuntime(22392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-21 09:10:55.675: E/AndroidRuntime(22392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-21 09:10:55.675: E/AndroidRuntime(22392): at dalvik.system.NativeStart.main(Native Method)
It took some serious looking and a total rework of what I was doing. but...
Basically I followed the tutorial Android ListView and ListActivity and then implemented the neat 'trick' described in Android ListView Adapter OnClickListener issue.
(I'm really having a hard time with this.)