GridView sorunu
18.04.2019 - 09:10
package com.example.wallpapergirisim;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Integer[] myImageArray={
R.drawable.thumb1,R.drawable.thumb2,
R.drawable.thumb3,R.drawable.thumb4
};
GridView myg;
ImageView myCurrentWallpaper;
WallpaperManager myWallManager;
Drawable myDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myg=findViewById(R.id.myg);
myCurrentWallpaper=findViewById(R.id.myCurrentWallpaper);
myg.setAdapter(new ImageAdapter(getApplicationContext()));
//UpdateMyWallpaper();
}
private void UpdateMyWallpaper(){
// myWallManager=WallpaperManager.getInstance(getApplicationContext());
//myDrawable=myWallManager.getDrawable();
// myCurrentWallpaper.setImageDrawable(myDrawable);
}
public class ImageAdapter extends BaseAdapter{
Context myContex;
public ImageAdapter(Context applicationContext) {
myContex=applicationContext;
}
@Override
public int getCount() {
return myImageArray.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView GridImageView;
if(convertView == null){
GridImageView=new ImageView(myContex);
GridImageView.setLayoutParams(new GridView.LayoutParams(512,512));
GridImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}else{
GridImageView=(ImageView) convertView;
}
GridImageView.setImageResource(myImageArray[position]);
return GridImageView;
}
}
}
Android için bir wallpaper uygulaması geliştiremeye çalıştırıoyrum kodlarım bunlar.Fakat programı hem emülatör hemde telefon da çalıştırdığımda uygulama ne yazıkki durdu diyor.Yardımcı olurmusunuz acaba nerde hatam var?
3
Görüntülenme
0 Beğeni