score:1
you can do a workaround.
instead of adding a viewpager you simply add a view extended by baseadapter.
in there you add a view with horizontallscroll. the click event you can trigger with the id of the corresponding view.
with this example you see how horizontall implement: http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/
please take notice that you must set your child width (in your case the picture) to match_parent. use a layout (that have match_parent) and in this layout you place your picture with wrap_content, for none stretching the picture.
edit 1:
first you create your horizontalscrollview layout like the following:
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<horizontalscrollview
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margintop="50dp" >
<linearlayout
android:id="@+id/hori_place_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</linearlayout>
</horizontalscrollview>
</linearlayout>
now you create a adapterview for your layout that you want to place in the linearlayout
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<imageview
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yourimage" />
</linearlayout>
now in your code you dynamically create and add the adapterview (like you have) to the linearlayout from your horizontalscrollview.
edit 2
public class horizontalscrollviewadapter extends baseadapter {
...
@override
public view getview(int pos, view convertview, viewgroup parent) {
view v = convertview;
imageview img_menu;
if(v==null){
inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);
v = inflater.inflate(r.layout.horiscvi, parent, false);
}
// at this you must add your customeviewlayout
return v;
}
}
and the adapter for customeview
public class customeviewadapter extends baseadapter {
...
@override
public view getview(int pos, view convertview, viewgroup parent) {
view v = convertview;
imageview img_menu;
if(v==null){
inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);
v = inflater.inflate(r.layout.list_makanan, parent, false);
}
img_menu = (imageview)v.findviewbyid(r.id.picture_menu_on_listview);
v.addview(img_menu);
return v;
}
}
edit 3
ok, now in your adapterview you have a section thats looking like the following:
arraylist<sitecontentdata> sitecontentdata = new arraylist<sitecontentdata>();
sitecontentdata.add(new sitecontentdata("one", "yourpicone"));
sitecontentdata.add(new sitecontentdata("two", "yourpictwo"));
sitecontentdata.add(new sitecontentdata("three", "yourpicthree"));
sitecontentdata.add(new sitecontentdata("four", "yourpicfour"));
horizontalscrollview = ((horizontalscrollview) findviewbyid(r.id.horizontalscrollview1));
sitepreview = ((linearlayout) findviewbyid(r.id.hori_linear));
for (sitecontentdata sitecontdata : sitecontentdata)
{
view convertview;
layoutinflater inflatercustomeshow =
(layoutinflater) getapplicationcontext().getsystemservice(
context.layout_inflater_service);
convertview = inflatercustomeshow.inflate(r.layout.customeimage, null);
view sitepreviewview =
sitecontentpreview.getview(getapplicationcontext(), convertview, sitecontdata);
sitepreview.addview(sitepreviewview);
}
in this you initialize your scrollview with the linearlayout inside of this. specially you adding the customeview inside of the linearlayout. the sitecontentdata is just a pojo thats hold two strings, the first is some sample text and the second is the path to the image in your project.
and the sitecontentpreview looks like this:
public class sitecontentpreview
{
public static view getview(context context, view convertview, sitecontentdata sitecontent)
{
view result = convertview;
if (result == null)
{
layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);
result = inflater.inflate(r.layout.customeimage, null);
}
textview sitenumber = ((textview) result.findviewbyid(r.id.custome_imageview_text));
imagebutton siteimage = ((imagebutton) result.findviewbyid(r.id.custome_image_view));
if (sitecontent != null)
{
sitenumber.settext(sitecontent.getsitenumber());
siteimage.setimageresource(integer.parseint(sitecontent.getsitecontentframe()));
}
return result;
}
}
just simple assigning.
that's all.
the horizontalscrollview layout you are right and here is the layout for the customeviewimage:
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<imageview
android:id="@+id/custome_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<textview
android:id="@+id/custome_imageview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview" />
</linearlayout>
that's all. enjoy. hope you achieve what you want.
public class sitecontentdata
{
private string sitenumber;
private string sitecontentframe;
public sitecontentdata(string sitenumber, string sitecontentframe)
{
this.sitenumber = sitenumber;
this.sitecontentframe = sitecontentframe;
}
public string getsitenumber()
{
return sitenumber;
}
public string getsitecontentframe()
{
return sitecontentframe;
}
}
Source: stackoverflow.com
Related Query
- How to add ViewPager that contain images into listview?
- Java: How can I add images from a file into a ResourceBundle?
- How do I search files in Eclipse so the results shows files that do NOT contain the search term?
- How to add a hyperlink into a Preference Screen (PreferenceActivity)
- How to resolve warning: You are installing software that contain unsigned content and authenticity and validity of this software can not established
- How to add an existing git repository (without an eclipse project) into eclipse?
- How to add an e4 eclipse part into Show View dialog
- How can I add class folders into Eclipse?
- How to add several views into one tab group in workbench perspective?
- How can i add images in source folder of a Maven Java Project?
- How to add one standalone project into another maven project
- How to export java project from eclipse into a jar file with images
- How to add C++ Library ( .a) file into C++/Java Hybrid Project
- How to add plugin to eclipse , So that I can run QML from Eclipse
- How do I import a multi module Maven project from SVN into Eclipse (Indigo) so that child modules can be built independently?
- how to add map.jar into myproject in android?
- How do you add a single parameter of an object with multiple parameters to a string from an arraylist of that object?
- How to read from text files inside a folder that has been imported into eclipse?
- Eclipse-RCP: How to add a plug-in with an application model into a perspective of a new RCP application?
- how to add library into eclipse
- Android + Eclipse How to import Enhanced ListView project into mine?
- How do I add a Skype provider into Eclipse Communication Framework?
- How to add one GridColumnGroup into another GridColumnGroup in nebula grid?
- How to add many sub directories with Java files into eclipse?
- How to add an extra URL mapping for an servlet that already mapped in Eclipse IDE 4.2?
- Eclipse - how to add a file that has right to left strings
- How to add an id to Listview
- How add Tycho packaging types into maven dialogs in Eclipse?
- How to add conventional jar into plugin (ClassNotFoundException, NoClassDefFoundError)?
- How do I add a single file back into my Eclipse project?
More Query from same tag
- Can't run a simple project (Maven - Spring - Eclipse)
- Restriction on J2SE inbuilt method
- Troubles with Bitbucket repositories using Eclipse
- Error when calling Native Code using JNI from a Jython module
- Eclipse unable to find the css file for GWT binder
- Swt shell/dialog force focus
- Create an Eclipse CVS NAS
- Is there a way to reinstall SUBVERSIVE?
- Collision detection not working in 2d android
- Is there a way to show a gif inside a SurfaceView?
- Google cloud messaging endpoint register fails locally
- Unable to set string to object
- Autocompletion in Pydev- Eclipse for wxpython
- Floating Action Button library to use in Eclipse
- Jenkins Plugin debug "Dependency ui-samples-plugin (1.509) doesn't exist"
- Memory Allocation Eclipse NDK Netbeans ImageProcessing
- PyDev, Eclipse & Python 3 - disable __module_not_in_the_pythonpath__ completition
- (Eclipse) Decoration Calculation Error on Ubuntu
- Eclipse will not read/run fxml files
- Annotation processor handles only recently changed classes
- Setting the JRE of java eclipse project in plugin programmatically
- False - Dead Code, OK. But nothing for True, why?
- Android requires compliance level 5.0 or 6.0
- How to fix this NoClassDefFoundError in my servlet
- Saving Javadoc across runs
- Using TelephonyManager in Android in a class that is NOT an activity
- No errors in eclipse, but the app crashes before it's fully loaded
- Install spindle in eclipse
- How to run ZeroMQ with Java?
- Can I set up a keybind/hot key/macro to paste a line into Eclipse?