I am a android developer and i want to develop an application. In this app, i want to show a gallery image slider.In this slider ,the focus able image see should large and place to middle point and other image see should be small to same bellow picture.
I also try the below code .It is also show the large focus able image but not same .
gallery.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.d("position", "" + arg3);
ProductByCategoryData productByCategoryData = AllProductByCategoryData
.getAllProductByCategoryData(arg2);
Constant.producdata = productByCategoryData;
Intent i = new Intent(ModeltypeActivity.this, OrderDetailInformation.class);
startActivity(i);
}
});
gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if (lastSelectedView != null)
{
lastSelectedView.setLayoutParams(new Gallery.LayoutParams(
lowLavelWidth, lowtLavelheight));// 150, 200//100, 150
}
arg1.setLayoutParams(new Gallery.LayoutParams(heighLavelWidth, heightLavelheight));// 220,
// 315//150, 200
lastSelectedView = arg1;
int vectorPosition = arg2;
ProductByCategoryData product = AllProductByCategoryData
.getAllProductByCategoryData(vectorPosition);
product_name.setText(product.getProduct_name());
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
Now how to show the gallery slider image same to above image.please help to me.It is Possibel ?
Related
I was trying to give background colour to selected items on GridView and I did it successfully using the following code-
gv.setOnItemClickListener(new OnItemClickListener() { // gv is object of GridView
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
gv.getChildAt(arg2).setBackgroundColor(Color.rgb(125, 125, 125));
}
});
Now I want to remove the given background colour when clicked on each item the next time. How can I do it ? Also, when clicked again the background colour should appear and on next click background colour should be removed.
You can check the current color background and then perform some conditional operation to update the view accordingly.
gv.setOnItemClickListener(new OnItemClickListener() { // gv is object of GridView
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
View view = gv.getChildAt(arg2);
int desiredBackgroundColor = android.graphics.Color.rgb(125, 125, 125);
ColorDrawable viewColor = (ColorDrawable) view.getBackground();
if(viewColor == null) {
view.setBackgroundColor(desiredBackgroundColor);
return;
}
int currentColorId = viewColor.getColor();
if(currentColorId == desiredBackgroundColor) {
view.setBackgroundColor(Color.TRANSPARENT);
} else {
view.setBackgroundColor(desiredBackgroundColor);
}
}
});
I have a slide puzzle game.
I want to change image on GridView by position(id).
How could I do that?
Try this
gridView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{
// You can get position of item or imageView and again you can set new image
// by setBackGround() by getting this position
}
});
I have a Grid View that have 4 images .So i want to identify which image has been clicked so that corresponding to that i can start a new activity .
So please help me how can i get this
I have tried this
dataView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
}
});
getView can be used for this purpose.for this in getView find View and apply onClicklistner their.to make all views clickable you need to setFocusable(false) on all focusable views.
I have got the solution
dataView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(),
links[arg2], Toast.LENGTH_SHORT).show();
}
});
int arg2 in the OnItemClick method specifies the position.Using that you can get the item clicked.
I have a spinner which drops down when a button is clicked. But when I am trying to set onItemSelectedListener, it is not taking the click events.
spnrLocation.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int arg2, long arg3) {
System.out.println("location clicked" + arg2);
edtLocation.setText(parent.getItemAtPosition(arg2).toString());
System.out.println("wfefe"
+ parent.getItemAtPosition(arg2).toString());
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
// try this
spnrLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println("location clicked" + i);
edtLocation.setText(spnrLocation.getSelectedItem().toString());
System.out.println("wfefe"
+ spnrLocation.getSelectedItem().toString());
}
});
Any View supports the android:clickable attribute (which lets you make any View behave like a Button).
There is also android:focusable.
I am new to android. I am using Intent to show full screen image and swipe between the images. The code is like:
(I am using grid to display images, Once I click on Image in grid I am calling intent)
Gridview_sponsor = (GridView) findViewById(R.id.gridViewSponsor);
Gridview_sponsor
.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0,
View arg1, int pos, long id) {
AlertDialog diaBox = AskOption(imagesName.get(pos)
.toString());
diaBox.show();
return true;
}
});
Gridview_sponsor.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + imagesName.get(position)),
"image/*");
startActivity(intent);
}
});
Previously it was working properly. But after uninstalling existing app it stop swapping.
In above code imagesName.get(position) contains the image path which I am assigning to ACTION_VIEW intent. But it is only showing the image in full screen and zoom in ,zoom out functionality is working fine.But the images are not getting swipe from that folder