所以我有一个带标签活动的应用程序,如果点击按钮(btlink),我想更改第一个标签的布局:
public class login extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.login, container, false);
final EditText etUtilizador = (EditText) getView().findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) getView().findViewById(R.id.etPassword);
final Button btLogin = (Button) getView().findViewById(R.id.btLogin);
Button btlink = (Button) getView().findViewById(R.id.btlink);
btlink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registerIntent;
registerIntent = new Intent(login.this, registar.class);
login.this.startActivity(registerIntent);
}
});
return rootView;
}
}
但它显示错误:“registerIntent = new Intent(login.this,registar.class);”
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin">
</TextView>
<EditText
android:id="@+id/etUtilizador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/section_label"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="Utilizador"
android:inputType="textPersonName"
android:textColor="@color/colorPrimaryDark" />
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/etUtilizador"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textColor="@color/colorPrimaryDark" />
<Button
android:id="@+id/btLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/etPassword"
android:layout_marginTop="41dp"
android:background="@color/colorAccent"
android:text="Login"
android:textAppearance="@style/BotaoRegisto" />
<Button
android:id="@+id/btlink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/btLogin"
android:layout_marginTop="49dp"
android:background="@color/colorAccent"
android:text="Registar"
android:textAppearance="@style/BotaoRegisto" />
<TextView
android:id="@+id/tvregisto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="TextView"
android:textColor="@color/colorPrimary"
tools:text="Se ainda nao tem conta registe-se aqui:" />
我只希望代码在我点击按钮时将布局更改为:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin">
</TextView>
<EditText
android:id="@+id/etNome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/section_label"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="Nome"
android:inputType="textPersonName"
android:textColor="@color/colorPrimaryDark" />
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/etNome"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="@color/colorPrimaryDark" />
<Button
android:id="@+id/btPedido"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/etNumero"
android:layout_marginTop="99dp"
android:background="@color/colorAccent"
android:elevation="0dp"
android:text="Enviar pedido de registo"
android:textAppearance="@style/BotaoRegisto" />
<EditText
android:id="@+id/etNumero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/etEmail"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Nº faturação ou série"
android:inputType="textPersonName"
android:textColor="@color/colorPrimaryDark" />
如果有人能够我感激不尽。
答案 0 :(得分:0)
首先设置 getView()
,而不是 final EditText etUtilizador = (EditText) rootView.findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) rootView.findViewById(R.id.etPassword);
final Button btLogin = (Button) rootView.findViewById(R.id.btLogin);
Button btlink = (Button) rootView.findViewById(R.id.btlink);
。
new Intent(getActivity(), registar.class);
并使用getActivity()
。
返回此片段当前与之关联的活动。
Intent registerIntent;
registerIntent = new Intent(getActivity(), registar.class);
getActivity().startActivity(registerIntent);
代码
Sub DarFormatoExelsEnFolder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Optimizar Macro
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Definir carpeta destino
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xlsx*"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
'Variable de libro abierto
Set wb = Workbooks.Open(Filename:=myPath & myFile)
'Confirmación de libro abierto
DoEvents
'Cambios al Workbook
Format wb
'Guardar y cerrar Workbook actual
wb.Close SaveChanges:=True
'Confirmación de libro cerrado
DoEvents
'Proximo libro
myFile = Dir
Loop
'Aviso de fin de ejecución
MsgBox "Operación Completada"
ResetSettings:
'Normalizar excel
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
'_______________________________________________________
Sub Format(wb As Workbook)
Dim i As Integer
Dim ws_num As Integer
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning
ws_num = ActiveWorkbook.Worksheets.Count
For i = 1 To ws_num
ActiveWorkbook.Worksheets(i).Activate
If Range("C1") <> "Company Name" Then
'Sheet format start
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Rows("1:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
'Pega o Llena información y logo predeterminados
Workbooks("REPORTE.xlsm").Worksheets("BACKEND").Range("F3:F3").Copy Destination:=Range("C1")
Workbooks("REPORTE.xlsm").Worksheets("BACKEND").Range("F4:F4").Copy Destination:=Range("C2")
Workbooks("REPORTE.xlsm").Worksheets("BACKEND").Range("F5:F5").Copy Destination:=Range("C3")
Workbooks("REPORTE.xlsm").Worksheets("BACKEND").Range("LogoBR").Copy Destination:=Range("A1")
Range("C4").Select
ActiveCell.FormulaR1C1 = ActiveSheet.Name & " - Actualizado el: " & ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
Range("C1:C4").Select
Range("C4").Activate
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End If
'Sheet format end
Range("A1").Select
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'Numera las hojas
ActiveWorkbook.Worksheets(i).Cells(1, 1) = 1
Next
'reactiva hoja inicial
starting_ws.Activate
End Sub
答案 1 :(得分:0)
变化
Intent registerIntent;
registerIntent = new Intent(login.this, registar.class);
login.this.startActivity(registerIntent);
要
Intent registerIntent = new Intent(getActivity(), registar.class);
startActivity(registerIntent);
还需要改变
final EditText etUtilizador = (EditText) rootView.findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) rootView.findViewById(R.id.etPassword);
final Button btLogin = (Button) rootView.findViewById(R.id.btLogin);
答案 2 :(得分:0)
public class login extends Fragment{
Context context;
@Override
onAttach(Activity activity){
context=(Context)activity;}
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
...
registerIntent = new Intent(context, registar.class);