Wrzucam wszystko bo już nie mam siły i nie wiem czemu nie działa. Nic się nie dzieje a wszystko chyba jest dobrze. Po kliknięciu na gridView a dokładnie na jeden z elementów ( zdjęcie + tekst) nic kompletnie nic się nie dzieje. Nie wiem czemu a najlepsze jest to że prawie identyczny kod w innej aplikacji i wszystko działa....
To w Main na czerwono powinno wyświetlać po kliknięciu na item cokolwiek a nic się nie dzieje (49 linia).
MAIN
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/fltKcl"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="60dp" />
<Button
android:id="@+id/fltTime"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="60dp" />
<Button
android:id="@+id/fltLevel"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="60dp" />
</LinearLayout>
<GridView
android:id="@+id/gridView"
android:numColumns="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
</GridView>
</LinearLayout>
</RelativeLayout>
sample_gridlayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="3dp">
<ImageView
android:id="@+id/os_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_marginTop="120dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:textColor="#FFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaa"
android:textSize="35sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFF"
android:text="aaaa "
android:textSize="20sp" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFF"
android:text="aaaa "
android:textSize="20sp" />
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFF"
android:text="aaaa"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
CustomAdapter
public class CustomAdapter extends BaseAdapter {
private List result, result2, result3,result4;
private Context context;
private int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity, List osNameList, List osNameList2,
List osNameList3, List osNameList4, int[] osImages) {
// TODO Auto-generated constructor stub
result=osNameList;
result2=osNameList2;
result3=osNameList3;
result4=osNameList4;
context=mainActivity;
imageId=osImages;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return result.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView os_text;
TextView os_text2;
TextView os_text3;
TextView os_text4;
ImageView os_img;
}
@SuppressLint("ViewHolder")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.sample_gridlayout, null);
holder.os_text =(TextView) rowView.findViewById(R.id.text1);
holder.os_text2 =(TextView) rowView.findViewById(R.id.text2);
holder.os_text3 =(TextView) rowView.findViewById(R.id.text3);
holder.os_text4 =(TextView) rowView.findViewById(R.id.text4);
holder.os_img =(ImageView) rowView.findViewById(R.id.os_images);
holder.os_text.setText(result.get(position).toString());
holder.os_text2.setText(result2.get(position).toString());
holder.os_text3.setText(result3.get(position).toString());
holder.os_text4.setText(result4.get(position).toString());
holder.os_img.setImageResource(imageId[position]);
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
return rowView;
}
}
MyDatabase
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "obrazki.db";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public Cursor getEmployees() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0 _id", "*"};
String sqlTables = "Obrazki";
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, null, null,
null, null, null);
c.moveToFirst();
return c;
}
}
Main
public class MainActivity extends AppCompatActivity {
private Cursor employees;
private MyDatabase db;
Button fltKcl, fltTime, fltLv;
GridView gridView;
public static List<String> osNameList = new ArrayList<String>();
public static List<String> osNameList2= new ArrayList<String>();
public static List<String> osNameList3= new ArrayList<String>();
public static List<String> osNameList4= new ArrayList<String>();
public static int[] osImages = {
R.mipmap.dwa,
R.mipmap.dwa,
R.mipmap.dwa,
R.mipmap.dwa,
R.mipmap.dwa,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addList();
fltKcl = (Button)findViewById(R.id.fltKcl);
fltLv = (Button)findViewById(R.id.fltLevel);
fltTime = (Button)findViewById(R.id.fltTime);
gridView = (GridView)findViewById(R.id.gridView);
gridView.setClickable(true);
gridView.setAdapter(new CustomAdapter(this, osNameList, osNameList2,
osNameList3, osNameList4, osImages));
gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
}
});
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(), "nic sie nie wyświetla", Toast.LENGTH_LONG).show();
}
});
}
public void addList(){
db = new MyDatabase(MainActivity.this);
employees = db.getEmployees(); // you would not typically call this on the main thread
do {
osNameList.add(employees.getString(2)+ " ");
osNameList2.add(employees.getString(6)+ " ");
osNameList3.add(employees.getString(5)+ " ");
osNameList4.add(employees.getString(7)+ " ");
} while (employees.moveToNext());
}
@Override
protected void onDestroy() {
super.onDestroy();
employees.close();
db.close();
}
}