我在android中只有一点exp .. nw我正在开发一个app ..它有一个编辑文本,一个按钮和一个Web视图......当用户按下时,用户可以在编辑文本中输入任何关键字按钮它必须搜索Android市场,结果必须在webview中显示..我知道如何在webview中显示一个网页....`
package com.example.webviewsimple;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView=(WebView)findViewById(R.id.webView1);
myWebView.loadUrl("http://www.google.com");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
`
这是用于搜索市场的代码
`
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://search?q=com.amazon.kindle"));
startActivity(i);
`
答案 0 :(得分:3)
您可以这样使用: this code is only work in android device
main_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="search on Google Play" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="searchData"
android:text="search" />
</LinearLayout>
活动:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_test);
}
public void searchData(View v) {
EditText ev = (EditText) findViewById(R.id.editText1);
String search = "market://search?q=";
search += ev.getText().toString();
if (v.getId() == R.id.button1) {
String appPackageName = getPackageName();
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(search));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
}
}
}
检查一下: