简体   繁体   English

为什么在我的应用程序中查看图库时,我无法获得正确的文本值?

[英]Why I am not able to getProper Text Value while Viewing Gallery in my application?

In My Application i have Implement the Simple Gallery Demo. 在我的应用程序中,我已实现了简单画廊演示。 Here i am going to set text Value according to user viewing the gallery. 在这里,我将根据查看图库的用户设置文本值。

Here is my Code for GetView method of Image Adapter class: 这是我的Image Adapter类的GetView方法的代码:

public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(this.myContext);

        i.setImageResource(this.myImageIds[position]);

        /* Image should be scaled as width/height are set. */
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        /* Set the Width/Height of the ImageView. */
        i.setLayoutParams(new Gallery.LayoutParams(300, 300));

        switch(position){

        case 0:
            productName.setText("dimond540_1");

            break;
        case 1:
            productName.setText("diamond540_2");

            break;
        case 2:
            productName.setText("diamond_ink_bottle_1");

            break;
        case 3:
            productName.setText("diamond_ink_bottle_2");

            break;
        case 4:
            productName.setText("diamond_ink_bottle_3");

            break;
        case 5:
            productName.setText("micarta_1");

            break;
        case 6:
            productName.setText("micarta_2");

            break;
        case 7:
            productName.setText("vac700_1");

            break;
        case 8:
            productName.setText("vac700_2");

            break;
        }
        return i;
    }
    /** Returns the size (0.0f to 1.0f) of the views
     * depending on the 'offset' to the center. */
    public float getScale(boolean focused, int offset) {
            /* Formula: 1 / (2 ^ offset) */
        return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
    }
}

Now the Proble is, While i am viewing the gallery image, text value is change. 现在的问题是,当我查看图库图像时,文本值正在更改。 But i am not able to get the textValue that i have set as second position and Second last position. 但是我无法获取设置为第二位置和第二倒数第二位置的textValue。

I have tryed many but every time i got all value but not the second position textValue and SecondLast position textValue. 我已经尝试了很多,但是每次我都获得了所有值,但第二个位置textValue和SecondLast位置textValue都没有。

So, whats wrong in my code? 那么,我的代码有什么问题呢?

I have solve My Question as below: 我已经解决了我的问题,如下所示:

I have made the Method in that class and in that method i change the TextValue and it works great. 我已经在该类中创建了方法,并且在该方法中,我更改了TextValue,并且效果很好。

Code: 码:

 public long getItemId(int position) { 

        switch(position){

        case 0:
            productName.setText("Dimond540(1)");

            break;
        case 1:
            productName.setText("Dimond540(2)");

            break;
        case 2:
            productName.setText("Diamond Ink Bottle(1)");

            break;
        case 3:
            productName.setText("Diamond Ink Bottle(2)");

            break;
        case 4:
            productName.setText("Diamond Ink Bottle(3)");

            break;
        case 5:
            productName.setText("Micarta(1)");

            break;
        case 6:
            productName.setText("Micarta(2)");

            break;
        case 7:
            productName.setText("Vac700(1)");

            break;
        case 8:
            productName.setText("Vac700(2)");

            break;
        }

        return position; 
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法从Android Gallery获得所选图像? - Why i am not able to get the selected image from Android Gallery? 我无法完成/关闭我的申请 - I am not able to finish/close my application Android应用程序设置为仅可在平板电脑上部署,但是为什么我仍然可以在手机上安装它? - Android application is set to be deployed on tablets only, but why am I still able to install it on my phone? 为什么我不能从相机拍摄图像,但可以从Android的Gallery获取图像? - Why i am not able to take image from camera but can able to get image from Gallery in android? 从Adobe 18.3版本应用程序共享pdf时,无法在“共享”菜单列表中看到我的Android应用程序 - I am not able to see my Android application in Share menu list while sharing pdf from adobe 18.3 version application 为什么我无法在我的应用程序中查看完整文本 - why am not able to view to complete text in my app 为什么我要在其中顶级运行应用程序时重新启动模拟器? - Why my Emulator get restarted while i am going top run the Application in it? 我无法在我的应用程序中打开google maps - i am not able to open google maps within my application 我无法理解为什么在我的 android 项目中解析 JSON 时显示异常,例如“JSONObject 无法转换为 JSONArray” - I am not able to get why showing exception while I parcing JSON like "JSONObject cannot be converted to JSONArray" in my android project 为什么我在操作栏中看不到向上箭头? - Why am I not able to see the up arrow in my action bar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM