2016-02-12 2 views
0

Надеюсь, я могу найти помощь здесь, потому что я ищу уже несколько недель для решения. Я использую android studio для программирования приложения.Почему мой намерение начинает пустую деятельность вместо правильной?

Когда я нажимаю кнопку «Пуск», чтобы начать новую операцию, она открывает пустую Activty вместо того, который должен был быть открыт.

Новая активность закодирована в манифесте, и никаких уведомлений об ошибках нет. Может быть, это не получило намерения?

Здесь MainActivity:

public class MainActivity extends AppCompatActivity { 


    Toolbar toolbar; 
    ViewPager viewPager; 
    TabLayout tabLayout; 

    FloatingActionButton fabtn1; 
    FloatingActionButton fabtn2; 
    FloatingActionButton fabtn3; 
    FloatingActionButton fabtn4; 

    int counter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     viewPager = (ViewPager) findViewById(R.id.viewpager); 

     ViewPagerAdapter1 viewPagerAdapter1 = new ViewPagerAdapter1(getSupportFragmentManager()); 
     viewPager.setAdapter(viewPagerAdapter1); 

     tabLayout = (TabLayout) findViewById(R.id.tablayout); 
     tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); 
     tabLayout.setupWithViewPager(viewPager); 
     tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 
      @Override 
      public void onTabSelected(TabLayout.Tab tab) { 

       viewPager.setCurrentItem(tab.getPosition()); 

      } 

      @Override 
      public void onTabUnselected(TabLayout.Tab tab) { 

      } 

      @Override 
      public void onTabReselected(TabLayout.Tab tab) { 

      } 
     }); 

     fabtn1 = (FloatingActionButton) findViewById(R.id.fab1); 
     fabtn1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       counter++; 

       if ((counter % 2) == 1) { 
        fabtn2.animate().translationY(-200).setDuration(300).alpha(1); 
        fabtn3.animate().translationY(-400).setDuration(320).alpha(1); 
        fabtn4.animate().translationY(-600).setDuration(340).alpha(1); 

       } 
       if ((counter % 2) == 0) { 
        fabtn2.animate().translationY(0).setDuration(300).alpha(0); 
        fabtn3.animate().translationY(0).setDuration(320).alpha(0); 
        fabtn4.animate().translationY(0).setDuration(340).alpha(0); 
       } 
      } 
     }); 

     //That's the Button, which should open the new Activity: 

     fabtn2 = (FloatingActionButton) findViewById(R.id.fab2); 
     fabtn2.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       Intent Startmessageqp = new Intent(MainActivity.this, MessagesQP.class); 
       startActivity(Startmessageqp); 
      } 
     }); 

     fabtn3 = (FloatingActionButton) findViewById(R.id.fab3); 

     fabtn4 = (FloatingActionButton) findViewById(R.id.fab4); 
    } 
}; 

Это новый вид деятельности, который, как предполагается, будет открыт после нажатия кнопки:

public class MessagesQP extends Activity { 

    EditText editText1; 
    EditText editText2; 
    FloatingActionButton fabMQ1; 
    FloatingActionButton fabQM2; 

    @Override 
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 
     super.onCreate(savedInstanceState, persistentState); 
     setContentView(R.layout.message_quickpost); 

     editText1 = (EditText) findViewById(R.id.editText); 
     editText2 = (EditText) findViewById(R.id.editText2); 
     fabMQ1 = (FloatingActionButton) findViewById(R.id.fabmq1); 
     fabQM2 = (FloatingActionButton) findViewById(R.id.fabmq2); 


    } 
} 

Пожалуйста, сообщите, если вам нужно больше некоторую информацию, чтобы помочь и I» Благодарю за каждый ответ!

NEW: Здесь messages_quickpost.xml

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

<EditText 
    android:layout_width="240dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText" 
    android:text="Type Message" 

    android:layout_marginTop="100dp" 
    android:layout_below="@+id/editText2" 
    android:layout_centerHorizontal="true" /> 

<EditText 
    android:layout_width="240dp" 
    android:layout_height="60dp" 
    android:inputType="textPersonName" 
    android:text="Contact Name" 
    android:id="@+id/editText2" 

    android:layout_alignParentTop="true" 
    android:layout_alignLeft="@+id/editText" 
    android:layout_alignStart="@+id/editText" 
    android:layout_marginTop="60dp" /> 


<android.support.design.widget.FloatingActionButton 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/fabmq1" 
    android:src="@drawable/send" 

    android:layout_alignBottom="@+id/editText" 
    android:layout_toRightOf="@+id/editText" 
    android:layout_toEndOf="@+id/editText" /> 

<android.support.design.widget.FloatingActionButton 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/fabmq2" 
    android:src="@drawable/account_plus" 
    android:layout_alignTop="@+id/editText2" 
    android:layout_toLeftOf="@+id/editText2" 
    android:layout_toStartOf="@+id/editText2" /> 


</RelativeLayout> 

Спасибо за помощь !!

+6

Пожалуйста, разместите макет 'message_quickpost' – AlbAtNf

+0

Я думаю, что вашему второму действию необходимо расширить' AppCompatActivity' так же, как ваша первая активность. Ваш код показывает, что он расширяет 'Activity'. Попробуй это. – rothloup

+0

Спасибо за ответ! Я пробовал то, что вы сказали, и, к сожалению, это не имеет никакого значения. Но спасибо за помощь! есть ли у вас другая идея? @rothloup –

ответ

1

он открывает пустую Активацию вместо того, который должен был быть открыт .

сделать обзор для ваших message_quickpost макета, я могу видеть, что содержит эти элементы editText1 , editText2 , fabMQ1 , fabMQ1 но не изменяя их свойства, как text, visibility и т.д.

setContentView(R.layout.message_quickpost); 

editText1 = (EditText) findViewById(R.id.editText); 
editText2 = (EditText) findViewById(R.id.editText2); 
fabMQ1 = (FloatingActionButton) findViewById(R.id.fabmq1); 
fabQM2 = (FloatingActionButton) findViewById(R.id.fabmq2); 

Вероятно, некоторые из ваших элементов имеют свойство видимости определяемый как INVISIBLE

+0

первый раз спасибо. второй я изменил свойства на visible: editText1 = (EditText) findViewById (R.id.editText); editText1.setVisibility (editText1.VISIBLE); Но он все еще не работает ... Я сделал все правильно? –

2

Спасибо за все ваши помощь, наконец, я нашел решение. Неправильная часть создания! Я включил его сейчас от:

@Override 
 
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 
 
     super.onCreate(savedInstanceState, persistentState); 
 
     setContentView(R.layout.message_quickpost);

к:

@Override 
 
    public void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.message_quickpost);

Это была проблема .. Теперь его работы! Все-таки спасибо всем вам!

+0

Это помогло мне! –

Смежные вопросы