Hallo Community ich habe mal wieder ein Problem und hoffe ihr könnte mir helfen.
Also das Problem ist das meine App immer abschmiert wenn ich auf den Tab fotos klicke.
Hier der Code. Wäre echt super wenn mir jemand helfen könnte.
Ich verzweifel hier langsam.
Main Klasse
Java
package info.app;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TabHost;
public class Info_ApplikationActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Standortinformation_activity.class);
spec = tabHost.newTabSpec("Standort").setIndicator("Standort",
res.getDrawable(R.drawable.ic_tab_standort))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Fachbereiche_activity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Fachbereiche").setIndicator("Fachbereiche",
res.getDrawable(R.drawable.ic_tab_fachbereich))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Links_activity.class);
spec = tabHost.newTabSpec("Links").setIndicator("Links",
res.getDrawable(R.drawable.ic_tab_link))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, GalleryActivity.class);
spec = tabHost.newTabSpec("Fotos FH").setIndicator("Fotos FH",
res.getDrawable(R.drawable.ic_tab_gallery))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
// was hier halt passieren soll
return true;
default:
return super.onKeyDown(keyCode, event);
}
}
}
Alles anzeigen
Grid View Klasse
Java
package info.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
public class GalleryActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.fotos);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this)); }
}
Alles anzeigen
Adapter Klasse
Java
package info.app;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
// TODO Auto-generated constructor stub
mContext= c;
}
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
//myButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.pic1
};
}
Alles anzeigen
Main XML
Java
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:background="@drawable/background1">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
</TableRow>
<TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
<TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
</TableLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Alles anzeigen
fotos.xml
Java
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
Alles anzeigen