|
|
|
[Android GridView Full Image] รบกวนด้วยครับ อยากถามเกี่ยวกับ Gridview ครับ |
|
|
|
|
|
|
|
รบกวนด้วยครับ อยากถามเกี่ยวกับ Gridview ครับ คือผมได้ลอง ทำตาม source code จาก https://www.thaicreate.com/mobile/android-sdcard-imageview-sqlite.html
Code (Android-Java)
public class MainActivity extends Activity {
List <String> ImageList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*** Get Images from SDCard ***/
ImageList = getSD();
// gridView1
final GridView gView1 = (GridView)findViewById(R.id.gridView1);
gView1.setAdapter(new ImageAdapter(this,ImageList));
// OnClick
gView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
View layout = inflater.inflate(R.layout.custom_full_imagedialog,
(ViewGroup) findViewById(R.id.layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.fullimage);
Toast.makeText(getApplicationContext(),
"Your selected : " + ImageList.get(position).toString(), Toast.LENGTH_SHORT).show();
}
});
}
private List <String> getSD()
{
List <String> it = new ArrayList <String>();
File f = new File(
android.os.Environment.getExternalStorageDirectory()
+ File.separator + Constance.PHOTO_ALBUM);
File[] files = f.listFiles ();
for (int i = 0; i <files.length; i++)
{
File file = files[i];
Log.d("Count",file.getPath());
it.add (file.getPath());
}
return it;
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private List <String> lis;
public ImageAdapter(Context c, List <String> li)
{
// TODO Auto-generated method stub
context = c;
lis = li;
}
public int getCount() {
// TODO Auto-generated method stub
return lis.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.show_image, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.textView1);
String strPath = lis.get(position).toString();
// Get File Name
String fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
textView.setText(fileName);
// Image Resource
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
Bitmap bm = BitmapFactory.decodeFile(strPath);
imageView.setImageBitmap(bm);
return convertView;
}
ตรงตัวแปร inflater บรรทัด 24 มันเป็นสีแดงครับ ไม่ทราบว่าผมทำผิดตรงไหนหรอครับ ผมทำใน Android Studio มันบอก cannot resolve method
Tag : Mobile, Android, Mobile
|
ประวัติการแก้ไข 2015-06-21 16:48:37 2015-06-21 16:49:20 2015-06-21 16:49:42 2015-06-21 16:50:42
|
|
|
|
|
Date :
2015-06-21 16:45:55 |
By :
yieldza |
View :
1308 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอดู Error message ตอนที่ Build หน่อยครับ
|
|
|
|
|
Date :
2015-06-22 10:55:58 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|