0

我必须开发一个android应用程序。从活动访问imageview到android中的片段

这里我使用片段的概念。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:id="@+id/_listDetails" 
> 

<RelativeLayout 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    android:orientation="horizontal" 

    android:id="@+id/layout" 
    > 
    <ImageView 
     android:id="@+id/pos" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_toLeftOf="@+id/neg" 
     android:src="@drawable/a_pos_off" /> 
     <ImageView 
     android:id="@+id/neg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_toLeftOf="@+id/imageView5" 
     android:src="@drawable/a_neg_off" /> 



         </RelativeLayout> 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_below="@+id/layout" 
android:orientation="horizontal" > 

<fragment 
    android:id="@+id/activity_main" 
    android:name="com.xmlparsing.MainActivity" 
    android:layout_width="0px" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 
<fragment 
    android:id="@+id/fragment2" 
    android:name="com.xmlparsing.SubCate" 
    android:layout_width="0px" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 
    </LinearLayout> 
    </RelativeLayout> 

在这里,我已经使用两个片段 ..They是,MainActivity.java和SubCate.java

public class AndroidListFragmentActivity extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment); 
     }} 

这里的正面形象是存在于fragment.xml之文件...在这里如果我必须点击这些积极的形象,这意味着必须增加文本大小的第二个Fragement(SubCate.java)的完整内容...

我该怎么办?请给我的解决方案来...

这是我第二块碎片(SubCate.java)代码:

@TargetApi(Build.VERSION_CODES.HONEYCOMB) 
public class SubCate extends Fragment 
{ 
    int count = 0, i, j; 
WebSettings webSettings; 
    WebView fullcontent; 
    ImageView positive,negative; 
    AndroidListFragmentActivity _listDetailsFrag; 
    View activityView; 

     @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    }  

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

    View view = inflater.inflate(R.layout.subcate, 
      container, false); 



    fullcontent = (WebView) view.findViewById(R.id.fullcontent); 

    Bundle bundle = getArguments(); 
    return view; 

     } 



     public void updateDetail(String articlefullcontent) { 

     _FullContent = articlefullcontent.substring(1); 
     fullcontent.setWebChromeClient(new WebChromeClient()); 
      webSettings = fullcontent.getSettings(); 


      fullcontent.getSettings(); 
      fullcontent.loadDataWithBaseURL(null, _FullContent, "text/html", "utf-8", null); 

     positive = ((ImageView)activityView.findViewById(R.id.pos)); 
      positive.setOnClickListener(new OnClickListener() { 


       public void onClick(View v) { 
        count++; 

         if (count == -1) 
         { 
         webSettings.setTextSize(WebSettings.TextSize.SMALLER); 
         positive.setImageResource(R.drawable.a_pos_off); 
         negative.setImageResource(R.drawable.a_neg_on); 
         } 
         else 
          if (count == 0) 
         { 
          webSettings.setTextSize(WebSettings.TextSize.NORMAL); 
          positive.setImageResource(R.drawable.a_pos_off); 
          negative.setImageResource(R.drawable.a_neg_off); 
         } 
         else 
       if (count >= 1) 
       { count=1; 
        webSettings.setTextSize(WebSettings.TextSize.LARGER); 
        positive.setImageResource(R.drawable.a_pos_on); 
        negative.setImageResource(R.drawable.a_neg_off); 
       } 


      } 
      }); 
       } 
      } 

我需要运行的应用程序,并单击ImageView的手段的fullcontent文本不增加价值...我怎么办?请帮助我,并提供一些解决方案?

回答

2

你的片段找不到相应的ImageView。编辑到下一个,并检查:

positive = (ImageView)getActivity().findViewById(R.id.pos);//use getActivity() Method 
+0

我明白了......谢谢...真的很开心.... – user2218667 2013-04-30 05:10:06

+0

欢迎你!祝你好运! – Daryn 2013-04-30 05:16:28