所以我正在尝试运行一个活动,并且在点击片段中的按钮时我得到“没有应用可以执行此操作”。
第一个主要活动意图声明:
Intent setTable = new Intent(this, setTable.class);
通过按钮点击运行的方法:
@Override
public void miscNext(){
startActivity(setTable);
}
点击片段按钮:
next.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
for(int i = 0; i < data.getDays(); i++){
String tempChecker = miscNum[i].getText().toString();
if(!tempChecker.isEmpty()){
data.setBreaks(i, Integer.parseInt(miscNum[i].getText().toString()));
} else{
break;
}
if(i == (data.getDays() - 1)){
data.setDoneNames(true);
}
}
data.initNamesArray();
if(data.isDoneNames()){
activityCommander.miscNext();
}
}
});
另一项活动,仅默认选项卡活动onCreate已更改:
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_table);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
final TextView day = new TextView(getApplicationContext());
final Spinner spinnerList[] = new Spinner[data.getSessions(mViewPager.getCurrentItem())];
final TextView session[] = new TextView[data.getSessions(mViewPager.getCurrentItem())];
day.setText(getDay(data.getFirstDay() + mViewPager.getCurrentItem()));
mViewPager.addView(day);
//Rules
LinearLayout.LayoutParams spinner = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams dayRule = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, data.getNamesArray());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
for(int i = 0; i < data.getDays(); i++){
spinnerList[i] = new Spinner(getApplicationContext());
session[i] = new TextView(getApplicationContext());
spinnerList[i].setAdapter(adapter);
mViewPager.addView(session[i], dayRule);
mViewPager.addView(spinnerList[i], spinner);
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
和logcat
11-23 14:21:07.865 9531-9531/com.example.user.timetable_test I/Timeline: Timeline: Activity_launch_request id: time:27674782
11-23 14:21:15.630 9531-9531/com.example.user.timetable_test V/ActivityThread: updateVisibility : ActivityRecord{7612187 token=android.os.BinderProxy@942882f {com.example.user.timetable_test/com.example.user.timetable_test.setup.Set_Up}} show : false
11-23 14:21:19.375 9531-9761/com.example.user.timetable_test D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
11-23 14:21:19.385 9531-9531/com.example.user.timetable_test W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
11-23 14:21:19.385 9531-9531/com.example.user.timetable_test W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
11-23 14:21:19.385 9531-9531/com.example.user.timetable_test W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
11-23 14:21:19.385 9531-9531/com.example.user.timetable_test W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
11-23 14:21:19.385 9531-9531/com.example.user.timetable_test W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
11-23 14:21:19.400 9531-9531/com.example.user.timetable_test I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@942882f time:27686319
这可能有点偏离主题,但有人知道如何以编程方式向标签添加小部件吗?
答案 0 :(得分:1)
如果您更改
会发生什么@Override
public void miscNext(){
startActivity(setTable);
}
通过
@Override
public void miscNext(){
startActivity(new Intent(this, setTable.class));
}
顺便说一下,如果我理解的话,Overriden方法public void miscNext()
在一个Activity中,对吗?
无论如何,除了问题之外的一个建议是在Java中,建议将第一个字母命名为大写字母,这意味着这样:
公共类SetTable
而不是
public class setTable
答案 1 :(得分:0)
如果您使用的是片段,而不是:
Intent setTable = new Intent(this, setTable.class);
使用:
Intent setTable = new Intent(getActivity, setTable.class);