2016-09-15 64 views
-1

我想說明基於內部對話框選項卡式所以爲了這個,我用This Library.如何在從BaseAdapter切換Tab時顯示Toast?

我能填充我的對話,也Tab是從tab_1中切換到Tab_2。但是當我點擊取消,確定或中性按鈕時,我沒有得到吐司。

請指導我如何在按鈕上使用初始化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

你在創建一個標籤對話框時傳遞** callback **實例的位置? –

+0

和TabDialogFragment是你自己的類嗎? –

+0

嗨拉胡爾..謝謝..其實我使用接口調用回調。沒有錯誤,但沒有顯示任何吐司或當我在對話框中滑動時沒有顯示tab_1和tab_2數據。 –

回答

0

其實從鏈接,您所提供的,他們在哪裏你逝去的背景,有一個問題經過MainActivity.this。因此,根據我的建議,只需在您的MainActivity.java類中實現這些回調,而不是適配器類。

+0

謝謝拉胡爾。但仍然沒有任何烤麪包,我越來越..我申請我的活動 –

+0

回電沒有做任何事情。這是主要問題。我已經嘗試過了。但我非常感謝你的友好行爲。 –

+0

請用最新的代碼更新您的問題。活動和適配器類。 –