2011-07-20 13 views
1

私の要件は:すべての販売ルートを一覧表示&ハイライトのデフォルト、それは最初のオプションにする必要があります。セールス担当者が他のオプションを選択した場合(デフォルトでは選択されていない)、ポップアップウィンドウが表示されます。ポップアップウィンドウには1つのフォームがあり、DBと話します。ポップアップウィンドウフォームを送信した後、前の画面に戻り、別の位置に移動することを許可する必要があります。Androidの1つのアクティビティをポップアップウィンドウ

私のコード

この初期リストアクティビティを参照してください。

ArrayList<Object> routeList = getWmRoute(); 
    ArrayList<String> routhPath = new ArrayList<String>(); 
    for(int i = 0; i<routeList.size();i++){ 
     routhPath.add(((WMRoute) routeList.get(i)).getDescription()); 
    } 

    ArrayAdapter ad = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,routhPath); 
    setListAdapter(ad); 
    final ListView list=getListView(); 
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
    list.setItemsCanFocus(true); 
    list.setTextFilterEnabled(true); 
    list.setItemChecked(0,true); 
    list.setSelection(0); 

これはこれはこれは

array_spinner=new String[2]; 
    array_spinner[0]="Rain"; 
    array_spinner[1]="Floods"; 
    Bundle bundle = this.getIntent().getExtras(); 
    param1 = bundle.getString("param1"); 

    Spinner s = (Spinner) findViewById(R.id.spinner1); 
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, array_spinner); 
    s.setAdapter(adapter); 
    final Button button = (Button) findViewById(R.id.submit); 

    button.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      Toast.makeText(SalesRouteDevitionActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show(); 
      Intent showContent = new Intent(getApplicationContext(),SalesRouteActivity.class); 

      Bundle bundle = new Bundle(); 
      bundle.putString("position", param1); 
      Intent mIntent = new Intent(); 
      mIntent.putExtras(bundle); 
      setResult(RESULT_OK, mIntent); 
      finish(); 
      startActivity(showContent); 


     } 
    }); 

私SalesRouteDevitionActivityクラスでリスナーメソッド

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    super.onListItemClick(l, v, position, id); 
    if(position !=0){ 
     Bundle bundle = new Bundle(); 
     int postion = position; 
     String aString = Integer.toString(postion); 
     bundle.putString("positon", aString); 
     Intent showContent = new Intent(getApplicationContext(),SalesRouteDevitionActivity.class); 
     // startActivityForResult(showContent,0); 
     startActivity(showContent); 

    } 
} 

です私のマニフェストファイル

<activity android:theme="@android:style/Theme.Dialog" android:name=".SalesRouteDevitionActivity" 
       android:label="Sales Route Diviation"> 
    </activity> 

仕上げのポップウィンドウの作業の後、その特定の場所にどのように行くことができますか?

あなたが選択した項目の位置のためのグローバル変数を作成することができます...事前

答えて

2

あなたはポップアップウィンドウが意図は、それが活動を開始し、ポップアップの活動になります。このstartActivityForResult(your_intent、requestCode)

を呼び出すthrought使用してそれを呼び出す開始どこからので、この方法

Bundle bundle = new Bundle(); 
bundle.putString("position", param1); 

Intent mIntent = new Intent(); 
mIntent.putExtras(bundle); 
setResult(RESULT_OK, mIntent); 
finish(); 

好きですポップアップはアクティビティを終了し、以前のアクティビティに戻ります。結果は

です。このアクティビティでは、このようにonActivityResultをオーバーライドします。

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if(resultCode==1){ 
     if(resultCode==RESULT_OK) 
      Toast.makeText(this, "SUCCESS", Toast.LENGTH_LONG).show(); 
     else 
      Toast.makeText(this, "Fail", Toast.LENGTH_LONG).show(); 
    } 
} 
+0

ご協力いただきありがとうございます。その実用的な罰金 – Piraba

1

おかげで私を助けてください。その後、前のアクティビティに戻ると、listView1.smoothScrollToPosition(int position)に電話します。

1

デフォルトではない位置にリストビューをフォーカスしたいのですか?そうであれば、positionでのリターンインテントとonActivityForResult()でその位置でフォーカスを設定する必要があります。問題がある場合は、 yahooまたはskype:fsoft_duonghvと私たちが議論します。

1

ポップアップウィンドウの新しいアクティビティを開始する代わりに、AlertDialogを作成できます。次に、あなたの活動を返すためにdismiss()を呼び出すことができます。

関連する問題