2013-10-28 5 views
-1

내 프로그램에서 다중 레벨 Listview를 보여주고 있지만 다른 활동을 호출 할 때마다 단편 탭이 나타나지 않습니다.조각 탭이 나타나지 않는다

나는이 위대한 튜토리얼 사용하고 있습니다 : http://www.androidbegin.com/tutorial/android-actionbarsherlock-viewpager-tabs-tutorial/

는 이미지 아래 참조 1 레벨의 ListView :

enter image description here

2 레벨의 ListView :

enter image description here

,

ListCategoryFragment.xml : -

public class ListCategoryFragment extends SherlockFragment implements OnItemClickListener { 

    ListView lview3; 
    ListCategoryAdapter adapter; 

    private ArrayList<Object> itemList; 
    private ItemBean bean; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
     // Get the view from fragmenttab1.xml 
     View view = inflater.inflate(R.layout.fragment_category_tab, container, false); 
     prepareArrayList(); 
     lview3 = (ListView) view.findViewById(R.id.listView1); 
     adapter = new ListCategoryAdapter(getActivity(), itemList); 
     lview3.setAdapter(adapter); 
     lview3.setOnItemClickListener(this); 

    return view; 
} 

private static final int categoryFirst = 0; 
private static final int categorySecond = 1; 
private static final int categoryThird = 2; 

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { 

    // Set up different intents based on the item clicked: 
    switch (position) 
    { 
     case categoryFirst: 
     Intent intent1 = new Intent(getActivity(), ListItemActivity.class); 
     intent1.putExtra("category", "Category - 1"); 
     startActivity(intent1);  
     break; 

     case categorySecond: 
     Intent intent2 = new Intent(getActivity(), ListItemActivity.class); 
     intent2.putExtra("category", "Category - 2"); 
     startActivity(intent2);  
     break; 

     case categoryThird: 
     Intent intent3 = new Intent(getActivity(), ListItemActivity.class); 
     intent3.putExtra("category", "Category - 3"); 
     startActivity(intent3);  
     break; 

     default: 
     break; 
    } 
} 

public void prepareArrayList() 
{ 
    itemList = new ArrayList<Object>(); 

    AddObjectToList("Category - 1"); 
    AddObjectToList("Category - 2"); 
    AddObjectToList("Category - 3"); 
} 

// Add one item into the Array List 
public void AddObjectToList(String title) 
{ 
    bean = new ItemBean(); 
    bean.setTitle(title); 
    itemList.add(bean); 
} 

@Override 
public void onSaveInstanceState(Bundle outState) { 
    super.onSaveInstanceState(outState); 
    setUserVisibleHint(true); 
} 

}

ListItemActivity.java:-

public class ListItemActivity extends SherlockFragmentActivity { 


static String URL = "http://www.site.url/tone.json"; 

static String KEY_CATEGORY = "item"; 
static final String KEY_TITLE = "title"; 

ListView list; 
ListItemAdapter adapter; 

/** Called when the activity is first created. */ 
@SuppressWarnings("deprecation") 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    getActionBar().setDisplayHomeAsUpEnabled(true); 
    setContentView(R.layout.activity_item_list); 

    final ArrayList<HashMap<String, String>> itemsList = new ArrayList<HashMap<String, String>>(); 
    list = (ListView) findViewById(R.id.listView1); 
    adapter = new ListItemAdapter(this, itemsList); 
    list.setAdapter(adapter); 

    Bundle bdl = getIntent().getExtras(); 
    KEY_CATEGORY = bdl.getString("category"); 

    if (isNetworkAvailable()) { 
     new MyAsyncTask().execute(); 
    } else { 

     AlertDialog alertDialog = new AlertDialog.Builder(ListItemActivity.this).create(); 
     alertDialog.setMessage("The Internet connection appears to be offline."); 
     alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 

      } 
     }); 
     alertDialog.show(); 
    } 
} 

public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getSupportMenuInflater(); 
    inflater.inflate(R.menu.main, menu); 

    return super.onCreateOptionsMenu(menu); 
} 

private Intent getDefaultShareIntent(){ 
     Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setType("text/plain"); 
     intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT"); 
     intent.putExtra(Intent.EXTRA_TEXT, "TEXT"); 
     startActivity(Intent.createChooser(intent, "Share via")); 
     return intent; 
    } 

/** The event listener for the Up navigation selection */ 
@Override 
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { 

    switch(item.getItemId()) 
    { 
     case android.R.id.home: 
      finish(); 
      break; 

     case R.id.menu_item_share: 
      getDefaultShareIntent(); 
      break; 
    } 
    return true; 
} 

private boolean isNetworkAvailable() { 
    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); 
    NetworkInfo info = cm.getActiveNetworkInfo(); 
    return (info != null); 
} 

class MyAsyncTask extends 
     AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> { 
    private ProgressDialog progressDialog = new ProgressDialog(
      ListItemActivity.this); 

    @Override 
    protected void onPreExecute() { 
     progressDialog.setMessage("Loading, Please wait....."); 
     progressDialog.show(); 
    } 

    final ArrayList<HashMap<String, String>> itemsList = new ArrayList<HashMap<String, String>>(); 

    @Override 
    protected ArrayList<HashMap<String, String>> doInBackground(
      String... params) { 
     HttpClient client = new DefaultHttpClient(); 
     // Perform a GET request for a JSON list 
     HttpUriRequest request = new HttpGet(URL); 
     // Get the response that sends back 
     HttpResponse response = null; 
     try { 
      response = client.execute(request); 
     } catch (ClientProtocolException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } catch (IOException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     // Convert this response into a readable string 
     String jsonString = null; 
     try { 
      jsonString = StreamUtils.convertToString(response.getEntity() 
        .getContent()); 
     } catch (IllegalStateException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } catch (IOException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     // Create a JSON object that we can use from the String 
     JSONObject json = null; 
     try { 
      json = new JSONObject(jsonString); 
     } catch (JSONException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 

     try { 

      JSONArray jsonArray = json.getJSONArray(KEY_CATEGORY); 

      for (int i = 0; i < jsonArray.length(); i++) { 

       HashMap<String, String> map = new HashMap<String, String>(); 
       JSONObject jsonObject = jsonArray.getJSONObject(i); 

       map.put("id", String.valueOf(i)); 
       map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE)); 
       itemsList.add(map); 
      } 
      return itemsList; 
     } catch (JSONException e) { 
      Log.e("log_tag", "Error parsing data " + e.toString()); 
     } 
     return null; 
    } 


    @Override 
    protected void onPostExecute(ArrayList<HashMap<String, String>> result) { 
     list = (ListView) findViewById(R.id.listView1); 
     adapter = new ListItemAdapter(ListItemActivity.this, itemsList); 
     list.setAdapter(adapter); 

     TextView lblTitle = (TextView) findViewById(R.id.text); 
     lblTitle.setText(KEY_CATEGORY); 

     this.progressDialog.dismiss(); 
     list.setOnItemClickListener(new OnItemClickListener() { 

      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 

       HashMap<String, String> map = itemsList.get(position); 

       Intent in = new Intent(ListItemActivity.this, ListItemDetailActivity.class); 
       in.putExtra(KEY_TITLE, map.get(KEY_TITLE)); 
       startActivity(in);     
      } 
     }); 
    } 
} 

}

답변

1

이것은 당신이에서 이동하기 때문에 정상적인 동작입니다 단편 활동을 정상 활동으로 보냅니다. 그러나 첫 번째 활동에만 탭이 있습니다.

올바른 방법은 의도와 새로운 활동을 제거하는 것입니다. 대신 조각 자체로 대체해야합니다.

예를 들어, 목록 항목에서 새로운 조각 활동에 대한 의도 호출을 중지하고 조각 자체를 호출하여 바꿉니다.

활동이 하나만 있으며 탭을 보유하고 다른 모든 활동은 단편이어야합니다. 동일한 활동 내에서 단편을 대체하면됩니다.

+0

나는 유용하게 쳤다. 7 분 후에 받아 들일 것이다. 네가 맞다. 나는 같은 액티비티에서 다른 단편을 부름으로써 노력했지만, 몇 가지 문제에 직면했다. 당신이 아무 문제가 없다면, 사실 나는 새로운 bie이고 이것을 만들려고 노력하고 있습니다. – Sonali

+0

당신은 어떤 종류의 문제에 직면하고 있습니까? –

+0

확실하니, 다음 라인에서 분 – Sonali

관련 문제