New Activity Not Opening
I'm an italian student developing an Android application with the latest version of Android Studio and with Android API 26 (Android Oreo). The application is very simple: 1. Main a
Solution 1:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/materia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imgButton"
android:layout_width="match_parent"
android:layout_height="120dp"/>
</LinearLayout>
~
public class Item_Adapter extends ArrayAdapter<Integer> {
public interface ItemListener {
void startNewIntent(int position);
}
ItemListener listener = null;
public void setItemListener(ItemListener item) {
listener = item;
}
public Item_Adapter(@NonNull Context context, int resource, @NonNull List<Integer> objects) {
super(context, resource, objects);
}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, parent, false);
}
ImageButton imgButton = convertView.findViewById(R.id.imageButton);
imgButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(listener != null) listener.startNewIntent(position);
}
});
ImageView imageView = convertView.findViewById(R.id.imageView);
imageView.setBackgroundResource(getItem(position));
return convertView;
}
}
Solution 2:
Please declare all activities into AndroidManifest file.
Post a Comment for "New Activity Not Opening"