2016-11-23 13 views
0

ImageViewにImageを設定します。グリッドビューのgridView.All画像のこの画像は、実行時にMySql DataBaseからフェッチされます。これは私のコードです。imageViewの画像をgridViewから表示します(データベースからすべての画像を取得します)

GalleryFragment.java

public class GalleryFragment extends Fragment { 
GridView grid; 
private List<User> userList; 



@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View rootView = inflater.inflate(R.layout.gallery, null); 

    grid=(GridView)rootView.findViewById(R.id.grid); 

    imagesFromDb(); 


    return rootView; 
} 
private void imagesFromDb() { 
    //Code Which Is Get all images from database 
    setData(); 
    } 
private void setData() { 
     AdapterGallery adapter = new AdapterGallery(getActivity(),userList); 
     grid.setAdapter(adapter); 
     grid.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 
      Intent i = new Intent(getActivity(), Galleryfullimage.class); 
      i.putExtra("id", position); 
      startActivity(i); 

     } 
    }); 

} 
} 

AdapterGallery.java

public class AdapterGallery extends BaseAdapter { 

    private Context mContext; 
    private List<User> userList; 

    public AdapterGallery(Context context, List<User> userList){ 
     mContext=context; 
     this.userList=userList; 

    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return userList.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; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     //View grid; 
     LayoutInflater inflater = (LayoutInflater) mContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.gallerysecond, null); 

     TextView en = (TextView) convertView.findViewById(R.id.grid_text); 
     ImageView imageView= (ImageView) convertView.findViewById(R.id.grid_image); 

     User contacts = userList.get(position); 
     en.setText(contacts.gall_name); 
     Picasso.with(mContext).load(ServerHelper.galleryimgpath+contacts.gall_img) 
       .placeholder(mContext.getResources().getDrawable(R.drawable.ic_launcher)) 
       .error(mContext.getResources().getDrawable(R.drawable.ramanisir)).into(imageView); 

     Log.e("Path", ServerHelper.galleryimgpath + contacts.gall_img); 

     return convertView; 

    } 
} 

Galleryfullimage.java

public class Galleryfullimage extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.galleryfullimage); 
    } 

} 

私は、レイアウトファイルを持っているGalleryfullimage.java?iにおける表示画像全体を何galleryfullimage.xml。そのファイルにはImageViewが1つあります。

私をガイドしてください。

ありがとうございます。 Galleryfullimage活動に

@Override 
    public void onItemClick(AdapterView<?> parent, View view, 
             int position, long id) { 
      Intent i = new Intent(getActivity(), Galleryfullimage.class); 
      i.putExtra("User_Image", userList.get(position).gall_img); 
      startActivity(i);   
    } 

次の使用:

+0

コードで直面している問題は何ですか? – Manishika

+0

ピカソは読み込んでいる画像ビューのサイズに応じて画像を読み込むため、画像全体を別途ロードする必要があります。 –

+0

グリッドビューで画像をクリックすると、画像全体が表示されません。 –

答えて

1
はとGalleryFragmentであなたのOnItemClickを変更

それはあなたがGallaryFullImage活動にのみ位置を通過しているようだ

public class Galleryfullimage extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.galleryfullimage); 
     String imageName = getIntent().getStringExtra("User_Image"); 
     //Now show this image to imageview using same picasso code 
     Picasso.with(this).load(ServerHelper.galleryimgpath+imageName) 
     .placeholder(getResources().getDrawable(R.drawable.ic_launcher)) 
     .error(getResources().getDrawable(R.drawable.ramanisir)) 
     .into(imageView/*Full image view*/); 
     } 
} 
+0

これは正常に動作します。 –

+0

あなたのために働く場合は、答えを受け入れます。 –

1

。 新しいアクティビティでは、特定のグリッドモデルのオブジェクト参照がありません。 したがって、ちょうど位置を渡す代わりに、Imageの完全なパスをこのようなインテントパラメータとして渡します。

grid.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
            int position, long id) { 
        User contacts = ((User) grid.getAdapter()).getItem(position); 
        Intent i = new Intent(getActivity(),Galleryfullimage.class); 
       //i.putExtra("id", position); 
        i.putExtra("Path", ServerHelper.galleryimgpath + contacts.gall_img); 
        startActivity(i); 
     } 
    }); 

このパスをGallaryfullimageアクティビティで取得して設定します。

+0

ありがとう...答え –

関連する問題