2016-09-15 11 views
-1

私はこのためにタブ付きのダイアログを表示したいのでこれを使用しますThis Library.BaseAdapterからタブを切り替えるとトーストを表示するには?

私はダイアログを作成することができますし、TabはTab_1からTab_2に切り替わります。しかし、キャンセルボタン、OKボタンまたはニュートラルボタンをクリックしているとき、私はトーストを得ていません。

ボタンのクリックでFragmentsToastを初期化する方法を教えてください。BaseAdapter私のコードは、リンクから実際にここに

public class ContactListAdapter extends BaseAdapter implements ISimpleDialogListener, ISimpleDialogCancelListener,IFragmentListener { 
slidingListItem.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      contactListItems = contactList.get(position); 
      String id_attende = contactListItems.getPhone(); 
      String id_attende_name = contactListItems.getName(); 


      TabDialogFragment.createBuilder(context, mFragmentManager) 
        .setTitle(id_attende_name) 
        .setSubTitle(id_attende) 
        .setTabButtonText(new CharSequence[]{"Calendar", "Summary"}) 
        .setPositiveButtonText("Ok") 
        .setNegativeButtonText("Cancel") 
        .setNeutralButtonText("Neutral") 
        .setRequestCode(REQUEST_TABBED_DIALOG) 
        .show(); 
     } 
    }); 

    return convertView; 
} 
@Override 
public void onCancelled(int requestCode) { 
    switch (requestCode) { 
     case REQUEST_TABBED_DIALOG: 
      Toast.makeText(context, "Dialog cancelled", Toast.LENGTH_SHORT).show(); 
      break; 
     default: 
      break; 
    } 
} 

@Override 
public void onNegativeButtonClicked(int requestCode) { 
    if (requestCode == REQUEST_TABBED_DIALOG) { 
     Toast.makeText(context, "Negative button clicked", Toast.LENGTH_SHORT).show(); 
    } 
} 

@Override 
public void onNeutralButtonClicked(int requestCode) { 
    if (requestCode == REQUEST_TABBED_DIALOG) { 
     Toast.makeText(context, "Neutral button clicked", Toast.LENGTH_SHORT).show(); 
    } 
} 

@Override 
public void onPositiveButtonClicked(int requestCode) { 
    if (requestCode == REQUEST_TABBED_DIALOG) { 
     Toast.makeText(context, "Positive button clicked", Toast.LENGTH_SHORT).show(); 
    } 
} 

@Override 
public void onFragmentViewCreated(Fragment fragment) { 
    int selectedTabPosition = fragment.getArguments().getInt(PageFragment.ARG_DAY_INDEX, 0); 
    View rootContainer = fragment.getView().findViewById(R.id.root_container); 
    Log.i(TAG, "Position: " + selectedTabPosition); 

    switch (selectedTabPosition) { 
     case 0: 
      selectedTabPositionZeroCase(rootContainer); 
      break; 
     case 1: 
      selectedTabPositionOneCase(rootContainer); 
      break; 
     default: 
      break; 
    } 


} 

private void selectedTabPositionZeroCase(View rootContainer) { 
    // add view in container for first tab 
    LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View tabProductDetailLayout = li.inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer); 
    TextView textView = (TextView) tabProductDetailLayout.findViewById(R.id.text_view); 
    textView.setText("hello: tab1"); 
} 

private void selectedTabPositionOneCase(View rootContainer) { 
    // add view in container for second tab 
    LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View tabProductDetailLayout2 = li.inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer); 

    TextView textView1 = (TextView) tabProductDetailLayout2.findViewById(R.id.text_view); 
    textView1.setText("hello: tab2"); 
} 

@Override 
public void onFragmentAttached(Fragment fragment) { 
    mMyScheduleFragments.add(fragment); 
} 

@Override 
public void onFragmentDetached(Fragment fragment) { 
    mMyScheduleFragments.remove(fragment); 
} 
} 
+0

ここで、タブダイアログを作成するときに**コールバック**インスタンスを渡していますか? –

+0

とTabDialogFragmentはあなたのクラスですか? –

+0

こんにちはrahul ..ありがとう..実際に私はコールバックインターフェイスを使用して呼び出しています。エラーは表示されませんが、ダイアログ内をスワイプしているときに、トーストを表示していないか、またはtab_1とtab_2のデータが表示されません。 –

答えて

0

ある

、あなたが提供している、彼らはMainActivity.thisあなたがコンテキストを渡していると問題があるを渡しています。だから私の提案ではアダプタではなく、MainActivity.javaクラスにこれらのコールバックを実装するだけです。

+0

Rahulさんありがとうございます。それでもまだ私にはどんなトーストもありません。私は私の活動に応募しました –

+0

コールバックは何もしていません。これは主な問題です。私はすでに試しました。私はあなたの友好的な行動に本当に感謝します。 –

+0

質問を最新のコードで更新してください。アクティビティークラスとアダプタークラスの両方。 –

関連する問題