intent.setClass(ScreenOne.this, ViewActivity.class);
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ScreenOne extends ListFragment {
String data[] = new String[] {
.....
.....
};
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, data);
setListAdapter(adapter);
}
public void onListItemClick (ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id); {
String itemname = new Integer(pos).toString();
Intent intent = new Intent();
intent.setClass(ScreenOne.this, ViewActivity.class);
Bundle b = new Bundle();
b.putString("defStrID", itemname);
intent.putExtras(b);
startActivity(intent);
}
}
}
Intent intent = new Intent(getActivity(), ViewActivity.class);
intent.putExtra(ViewActivity.EXTRA_ITEM_NAME, itemname);
startActivity(intent);
class ViewActivity {
public static final String EXTRA_ITEM_NAME = "defStrID";
...
onCreate(..){
...
String itemname = getIntent.getStringExtra(EXTRA_ITEM_NAME);
...
}
}
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ru.aam.pril.R;
public class ViewActivity extends Activity {
private WebView web;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
Bundle bundle = getIntent().getExtras();
String itemname = "n" + bundle.getString("defStrID");
Context context = getBaseContext();
String text = readRawTextFile(context,
getResources().getIdentifier(itemname, "raw", "ru.aam.pril"));
web = (WebView) findViewById(R.id.webview);
web.loadDataWithBaseURL("file:///android_res/raw/",
"<!Doctype html><html><head><meta charset=utf-8></head><body>"
+ text + "</body></html>", "text/html", "utf-8", "");
}
public static String readRawTextFile(Context ctx, int resId)
{
InputStream inputStream = ctx.getResources().openRawResource(resId);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
StringBuilder text = new StringBuilder();
try {
while ((line = buffreader.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException e) {
return null;
}
return text.toString();
}
}