2014-07-10 3 views
0

조각 모음을 포함한 Android 바 활동 구조와 관련하여 질문이 있습니다. 막대 요소를 통합하고 조각을 만드는 등 MainMenuActivity가 있습니다. 버튼을 사용하여 조각 내에서 작업 할 수있게하려고합니다. 조각에서 타이머를 시작하고 싶지만 조각을 열기 전에 응용 프로그램이 충돌합니다. 여기 그런조각 모음이있는 Android 바 활동

07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.os.Handler.handleCallback(Handler.java:733) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.os.Handler.dispatchMessage(Handler.java:95) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.os.Looper.loop(Looper.java:157) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at android.app.ActivityThread.main(ActivityThread.java:5356) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at java.lang.reflect.Method.invoke(Method.java:515) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
07-10 09:14:08.010: E/AndroidRuntime(8615):  at dalvik.system.NativeStart.main(Native Method) 

MainMenuActivity.java 파일입니다 : 여기

은 내가 오류입니다

package com.example.client; 

import org.slf4j.LoggerFactory; 
import android.annotation.SuppressLint; 
import android.app.ActionBar; 
import android.app.ActionBar.Tab; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Fragment; 
import android.app.FragmentTransaction; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 
import android.content.ServiceConnection; 
import android.location.Location; 
import android.os.Bundle; 
import android.os.IBinder; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 
import com.example.uadclient.R; 



public class MainMenuActivity extends Activity { 

Logger LOG = LoggerFactory.getLogger(MainMenuActivity.class); 

private static final String TAB_KEY_INDEX = "tab_key"; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // ActionBar 
    ActionBar actionbar = getActionBar(); 
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    // create new tabs and and set up the titles of the tabs 
    ActionBar.Tab mFindTab = actionbar.newTab().setText(
      getString(R.string.ui_tabname_find)); 
    ActionBar.Tab mChatTab = actionbar.newTab().setText(
      getString(R.string.ui_tabname_chat)); 
    ActionBar.Tab mMeetTab = actionbar.newTab().setText(
      getString(R.string.ui_tabname_meet)); 
    ActionBar.Tab mPartyTab = actionbar.newTab().setText(
      getString(R.string.ui_tabname_party)); 

    // create the fragments 
    Fragment mFindFragment = new FindFragment(); 
    Fragment mChatFragment = new ChatFragment(); 
    Fragment mMeetFragment = new MeetFragment(); 
    Fragment mPartyFragment = new PartyFragment(); 

    // bind the fragments to the tabs - set up tabListeners for each tab 
    mFindTab.setTabListener(new MyTabsListener(mFindFragment, 
      getApplicationContext())); 
    mChatTab.setTabListener(new MyTabsListener(mChatFragment, 
      getApplicationContext())); 
    mMeetTab.setTabListener(new MyTabsListener(mMeetFragment, 
      getApplicationContext())); 
    mPartyTab.setTabListener(new MyTabsListener(mPartyFragment, 
      getApplicationContext())); 

    // add the tabs to the action bar 
    actionbar.addTab(mFindTab); 
    actionbar.addTab(mChatTab); 
    actionbar.addTab(mMeetTab); 
    actionbar.addTab(mPartyTab); 


    // restore to navigation 
    if (savedInstanceState != null) { 
     Toast.makeText(getApplicationContext(), 
       "tab is " + savedInstanceState.getInt(TAB_KEY_INDEX, 0), 
       Toast.LENGTH_SHORT).show(); 

     actionbar.setSelectedNavigationItem(savedInstanceState.getInt(
       TAB_KEY_INDEX, 0)); 
    } 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.main, menu); 
    return true; 
} 


protected void onDestroy(){ 
    super.onDestroy(); 

} 



@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 

    } 
    return false; 
} 

// onSaveInstanceState() is used to "remember" the current state when a 
// configuration change occurs such screen orientation change. This 
// is not meant for "long term persistence". We store the tab navigation 

@Override 
protected void onSaveInstanceState(Bundle outState) { 
    super.onSaveInstanceState(outState); 
    Toast.makeText(
      this, 
      "onSaveInstanceState: tab is" 
        + getActionBar().getSelectedNavigationIndex(), 
      Toast.LENGTH_SHORT).show(); 
    outState.putInt(TAB_KEY_INDEX, getActionBar() 
      .getSelectedNavigationIndex()); 

} 


} 

// TabListenr class for managing user interaction with the ActionBar tabs. The 
// application context is passed in pass it in constructor, needed for the 
// toast. 

class MyTabsListener implements ActionBar.TabListener { 
public Fragment fragment; 
public Context context; 

public MyTabsListener(Fragment fragment, Context context) { 
this.fragment = fragment; 
    this.context = context; 

} 

@Override 
public void onTabReselected(Tab tab, FragmentTransaction ft) { 
    Toast.makeText(context, "Reselected!", Toast.LENGTH_SHORT).show(); 

} 

@Override 
public void onTabSelected(Tab tab, FragmentTransaction ft) { 
    Toast.makeText(context, "Selected!", Toast.LENGTH_SHORT).show(); 
ft.replace(R.id.fragment_container, fragment); 
} 

@Override 
public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
Toast.makeText(context, "Unselected!", Toast.LENGTH_SHORT).show(); 
    ft.remove(fragment); 
} 

/** 
* A placeholder fragment containing a simple view. 
*/ 
public static class PlaceholderFragment extends Fragment { 


} 

@SuppressLint("CutPasteId") 
public void onClick(View v) { 

switch(v.getId()) { 
case R.id.checkBox1: 
    { 
     try { 
      EditText inputIP = (EditText) findViewById(R.id.editText1); 
      String ip = inputIP.getText().toString(); 

      EditText inputhost = (EditText) findViewById(R.id.editText2); 
      int host = Integer.parseInt(inputhost.getText().toString()); 

      if (inputIP.getText().length() >   &&((inputhost.getText().length()>   0))) { 
       send(ip, host); 

      } 
      else { 
       inputIP.setError("Cannot be empty"); 
       inputhost.setError("Cannot be empty"); 

       } 
     } catch (TException e) { 
      // LOG.error("Sending failed: ", e); 
      } 

     break; 


    }  
    //Show Coordinates 
    case R.id.button1: 
    { 

     LocationProviderService locService = null; 
     Location currentLoc = locService.getLastGPSProviderPosition(); 
     GeographicPointReference gpr = new GeographicPointReference(); 
     BoundingBox bb = new BoundingBox(); 

     gpr.setLatitude(currentLoc.getLatitude()); 
     gpr.setLongitude(currentLoc.getLongitude()); 

     bb.setUpperright(gpr); 
     bb.setLowerleft(gpr); 

     TextView tv = new TextView(locService); 
     tv.setText(" "+bb.setLowerleft(gpr)+" "); 
     setContentView(tv); 

    } 
     return; 
     } 

} 

private void setContentView(TextView tv) { 
    // TODO Auto-generated method stub 

} 

private EditText findViewById(int edittext1) { 
    // TODO Auto-generated method stub 
    return null; 
}} 

타이머를 포함하는 조각은,

package com.example.client; 

import android.annotation.SuppressLint; 
import android.app.Fragment; 
import android.os.Bundle; 
import android.os.CountDownTimer; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.TextView; 

import com.example.uadclient.R; 


public class ChatFragment extends Fragment { 

    private MalibuCountDownTimer countDownTimer; 
    private long timeElapsed; 
    private boolean timerHasStarted = false; 

    private TextView text; 
    private TextView timeElapsedView; 

    private final long startTime = 50000; 
    private final long interval = 1000; 
    private Button buttonTimer; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 


     LinearLayout rr = (LinearLayout) inflater.inflate(R.layout.chatfragment, 
      container, false); 


     text = (TextView) rr.findViewById(R.id.timer); 
     timeElapsedView = (TextView) rr.findViewById(R.id.timeElapsed); 



     countDownTimer = new MalibuCountDownTimer(startTime, interval); 
     text.setText(text.getText() + String.valueOf(startTime)); 

     buttonTimer = (Button) rr.findViewById(R.id.button1); 

     buttonTimer.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
      Fragment fragment = new FindFragment(); 
      android.app.FragmentTransaction ft = getFragmentManager() 
        .beginTransaction(); 

      switch (v.getId()) { 

      case R.id.button1: 
      { 
       if (!timerHasStarted) 
        { 
         countDownTimer.start(); 
         timerHasStarted = true; 
         buttonTimer.setText("Start"); 
        } 
       else 
        { 

         countDownTimer.cancel(); 
         timerHasStarted = false; 
         buttonTimer.setText("RESET"); 
        } 

      }} 

     // ft.commit(); 
      } 


     }); 



     return rr; 
     } 

} 
ChatFragment.java

입니다

및 chatfragment.xml

,
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.30" 
     android:orientation="vertical" > 

     <Button 
     android:id="@+id/button" 
     android:text="Start" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <TableLayout 
     android:padding="10dip" 
     android:layout_gravity="center" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <TableRow> 
      <TextView 
       android:id="@+id/timer" 
       android:text="Time: " 
       android:paddingRight="10dip" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/timeElapsed" 
       android:text="Time elapsed: " 
       android:paddingRight="10dip" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 
</LinearLayout> 
+0

을 볼 수있는 동일한에 대한 자세한 내용은

그는 지원 라이브러리를 사용하지 않는 것 ActionBarActivity' –

+0

@MD을 확장합니다. – Marius

+0

다음 행은 무엇입니까 : ActivityThread.java:5356? – masmic

답변

0

당신은

getFragmentManager().executePendingTransactions(); 당신이 조각에 대한 새로운 트랜잭션을 수행하기 전에 다른 모든 트랜잭션이 완전히 실행 확인하기 위해 사용해야합니다. 당신이 시도이`공용 클래스 MainMenuActivity을 문제 here

+0

힌트를 보내 주셔서 감사합니다! MainMenuActivity 또는 Fragment ChatFragment 내부를 의미합니까? –

+0

새로운 채팅 조각을 만들기 전에'MainMenuActivity'에 들어 있어야합니다. – Anuj