由于一些奇怪的原因,setContentView()没有调用我的LoginActivity类。它显示布局但不读取上下文?我添加了一个按钮和onclicklistener,它没有被调用。仅显示布局。
这是非常奇怪的我已经看到完成了每一件事但是LoginActivity被调用了吗?是因为嵌套布局吗?
LoginActivity
public class LoginActivity extends BaseActivity implements View.OnClickListener {
@BindView(R.id.button_signin)
Button button_signin;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
//button_login.setOnClickListener(this);
button_signin.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_signin:
Toast.makeText(this, "test321", Toast.LENGTH_SHORT).show();
break;
}
}
}
BaseActivity
public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/ghostWhiteColor"
android:orientation="vertical"
android:context="test.testing.core.BaseActivity"
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/f_roboto_bold"
android:textColor="@color/holo_blue_light"
android:gravity="center"
android:paddingTop="140dp"
android:textSize="50sp"
android:text="@string/brandingtext" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="200dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/login_username"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="text"
android:backgroundTint="@color/ghostWhiteColor"
android:hint="@string/hint_name"
android:singleLine="true"
android:textColor="@color/myBlack"
android:textColorHighlight="@color/antiqueWhiteColor"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/login_password"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="textPassword"
android:backgroundTint="@color/ghostWhiteColor"
android:hint="@string/hint_name"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button_signin"
android:layout_width="125dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/blue_oval"
android:text="@string/btn_login"
android:textColor="@color/ghostWhiteColor" />
<TextView
android:id="@+id/label_register"
android:layout_width="match_parent"
android:layout_height="60dp"
android:fontFamily="@font/f_roboto_lightitalic"
android:gravity="center"
android:text="hello321"
android:textColor="@color/myBlack"
android:textSize="@dimen/fui_heading_padding_bottom" />
</LinearLayout>
</RelativeLayout>
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.luxx.market.propg.luxx">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BaseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".core.activities.LoginActivity">
</activity>
<activity android:name=".core.activities.RegisterActivity">
</activity>
</application>
</manifest>
答案 0 :(得分:0)
您从BaseActivity开始,这是不正确的,baseactivity应该是一个抽象类。
将此内容放入loginactivity并将其从基本活动中删除
library(shiny)
ui <- fluidPage(
mainPanel(
tabsetPanel(
tabPanel("Information required for the model",
sliderInput("Reservoirs", label = h3("Total Number of Reservoirs"),
min = 1, max = 50,
value = 10),
sliderInput("Municipalities", label = h3("Total Number of Municipalities Served by the Reservoirs"),
min = 1, max = 150,
value = 15)
),
tabPanel("Uploading files and other information",
fileInput("ResName", "What are the names of the reservoirs?",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
fileInput("MunicipName", "What are the names of the municipalities?",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
)
),
tabPanel("Summary of Inputs", tableOutput("Summary_Page_1a"), tableOutput("Summary_Page_1b"), tableOutput("Summary_Page_1c")),
tabPanel("Summary of csv files", tableOutput("Summary_Page_2"))
)))
server <- function(input, output) {
names_of_reservoirs<-reactive(nrow(input$ResName))
names_of_municipalities<-reactive(nrow(input$MunicipName))
output$Summary_Page_1a<-renderText({(paste0("There are ",
input$Reservoirs,
" reservoirs <br> Serving ",
input$Municipalities,
" municipalities."
))
})
output$Summary_Page_1b<- renderText({if ((names_of_reservoirs)==input$Reservoirs){
" "
}else{
"ERROR! The number of reservoirs and the number of reservoir names do not match"}
})
output$Summary_Page_1c<- renderText({if ((names_of_municipalities)==input$Municipalities){
" "
}else{
"ERROR! The number of Municipalities and the number of muncipality names do not match"}
})
}
shinyApp(ui = ui, server = server)