2013-12-04 2 views
1

Я очень новичок в этом.Нажмите на текст, чтобы открыть картинку

Как я могу щелкнуть по тексту и открыть его, чтобы открыть изображение, которое сохраняется в приложении?

Это то, что у меня есть до сих пор, но у меня есть ошибки, я использую Фрагменты, и я не знаю, правильно ли я делаю это.

Спасибо!

Это то, что я сейчас в Fragment_6.java:

package com.rufflez.swipeytabs; 

import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

import com.actionbarsherlock.app.SherlockFragment; 

public class Fragment_6 extends SherlockFragment{ 

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 
    return inflater.inflate(R.layout.fragment_6, container, false); 


TextView tv = (TextView) findViewById(R.id.textView1); 
tv.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View v) { 
String url = "http://androidcookbook.com/seam/resource/graphicImage/escapedn.png";    
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(url)); 
startActivity(intent); 
} 
}); 
} 

} 

в fragment_6.xml:

<?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" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:gravity="left" 
    android:clickable="true" 
    android:text="@string/procedures1" 
    /> 
+0

Вы написали логику после возвращения , поэтому остальная часть кода недостижима, напишите строку «return» в конце метода onCreateView(). –

ответ

1

Изменения в

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 
View v =inflater.inflate(R.layout.fragment_6, container, false); 
// inflate the layout 

TextView tv = (TextView) v.findViewById(R.id.textView1); 
// initialize textview using inflated view object 
tv.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View v) { 
String url = "http://androidcookbook.com/seam/resource/graphicImage/escapedn.png";    
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(url)); 
startActivity(intent); 
} 
}); 
reuturn v; // return view 
} 
+0

спасибо! Я попытался использовать это и, похоже, работает. Знаете ли вы, как я могу открыть изображение из drawable? – Catherine

Смежные вопросы