everyone
i have a problem with my project
here is my search.java code
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class Search extends Activity {
TextView error,br2;
Spinner namjal2;
String i,returnString2,jln;
String[] jalan = {"A.Yani", "Ambengan", "Anjasmoro","Baliwerti","Basuki Rahmat","Bintoro","Ciliwung","Citarum","Citandui","Darmo Daya","Darmokali","Dharmawangsa","Dinoyo","Embong Kemiri","Embong Malang"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
br2=(TextView)findViewById(R.id.berita2);
namjal2=(Spinner)findViewById(R.id.namjalSearch);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, jalan);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
namjal2.setAdapter(aa);
}
public void clickHandler(View view){
Intent a = null;
switch (view.getId()){
case R.id.find:
jln = jalan[namjal2.getSelectedItemPosition()];
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nama_jalan", jln));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.1.3/android/searchInfo.php", postParameters);
String result = response.toString();
//parse json data
try{
returnString2 = "";
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id_kepadatan: "+json_data.getInt("id_kepadatan")+
", username: "+json_data.getString("username")+
", nama_jalan: "+json_data.getString("nama_jalan")+
", status: "+json_data.getString("status")+
", tanggal: "+json_data.getString("tanggal")+
", waktu: "+json_data.getString("waktu")+
", keterangan: "+json_data.getString("keterangan")
);
if(result.equals(null)){
//Get an output to the screen
returnString2 += "Data tidak ada";
}
else{
returnString2 += "\n" + json_data.getString("nama_jalan") + " mengalami "+ json_data.getString("status")+ " pada "+ json_data.getString("tanggal")+ " waktu "+ json_data.getString("waktu")+ " karena "+ json_data.getString("keterangan");
}
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
try{
br2.setText(returnString2);
}
catch(Exception e){
Log.e("log_tag","Error in Display!" + e.toString());;
}
}
catch (Exception e) {
Log.e("log_tag","Error in http connection!!" + e.toString());
}
break;
case R.id.back:
a = new Intent(this, Menu.class);
startActivity(a);
break;
}
}
}
and here is my search.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="PENCARIAN BERITA TERBARU"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Masukkan Nama Jalan"/>
<Spinner
android:id="@+id/namjalSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dip"
android:layout_marginBottom="20dip"
android:singleLine="true"/>
<Button android:id="@+id/find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="250dip"
android:text="Find"
android:onClick="clickHandler"/>
<TextView
android:id="@+id/berita2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dip"
android:layout_marginTop="130dip"
android:layout_marginLeft="190dip"
android:textColor="#372c24"
android:text="BACK"/>
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="125dip"
android:layout_marginLeft="258dip"
android:src="@drawable/back"
android:background="@null"
android:onClick="clickHandler"/>
<Button android:id="@+id/cariPeta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="125dip"
android:text="Cari Peta"
android:onClick="clickHandler"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
my goal is when i click the “cariPeta” button, it will show the map from the street which choosen
for example, if spinner pointing one name of the street (ex : “A.Yani” street) … then, when i click “cariPeta” button,,,it will show the map of “A.Yani” street in google map
my problem is, i dont know what code should i write….can you tell me? i will much appreciate it because this project is very important to me
Thank You…..
Ok let me guide you.
You need to write click event of button.
On click of that button getSelectedIndex of spinner (there is a readymade method for it in spinner obj).
After receiving index value fetch text from string array.
Then Map will come in picture. But to deal with the map you need pair of lat/long.
Using lat/long you can show any point on map.