Reputation: 211
I hav only a little exp in android.. nw I am developing an app ..it has one edit text and one button and a web view...the user can enter any keyword in edit text when the user presses the button it has to search the android market and the result has to displa in webview..nw i knw hw to display a web page in the 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;
}
}
`
this is the code used to search the market
`
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://search?q=com.amazon.kindle"));
startActivity(i);
`
Upvotes: 0
Views: 1503
Reputation: 18978
you can use this way : 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>
in activity:
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);
}
}
}
check this :
Upvotes: 3