我的java组件声明有一个未知的类,但我清楚地在我的xml文件中声明了新的id
content_user_response.xml
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/gotomoodanalysis"
android:layout_below="@+id/frame4"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Run Code Online (Sandbox Code Playgroud)
UserResponse.java
package com.example.enxin.emotiontracker;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class UserResponse extends AppCompatActivity {
Button gotomoodanalysis;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_response);
}
gotomoodanalysis = (Button)findViewById(R.id.next1);
}
Run Code Online (Sandbox Code Playgroud)
我需要帮助.提前致谢
我试图将Label放在按钮内的图像下并居中.我有一个按钮的自定义渲染器,但由于某种原因,我无法生成所需的输出.代码在C#Xamarin中.
XAML代码:
<Controls:ExtendedButton
VerticalOptions="EndAndExpand"
HorizontalOptions="CenterAndExpand"
x:Name="search"
Text="Search"
Image="Completed.png"
IsEnabled="{Binding IsLoading}"
Command="{Binding SearchCommand}"
WidthRequest ="120"
HeightRequest ="120"
TextColor="#FFFFFF"
>
</Controls:ExtendedButton>
Run Code Online (Sandbox Code Playgroud)
C#iOS CustomRenderer
public class ExtendedButtonRenderer : ButtonRenderer
{
UIButton btn;
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
btn = (UIButton)Control;
CGRect imageFrame = btn.ImageView.Frame;
imageFrame.Y = 0;
imageFrame.X = (btn.Frame.Size.Width / 2) - (imageFrame.Size.Width / 2 );
btn.ImageView.Frame = imageFrame;
var labelSize = new NSString(btn.TitleLabel.Text).
GetBoundingRect(
new CGSize(btn.Frame.Width, float.MaxValue),
NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes() { Font = UIFont.SystemFontOfSize(8) …Run Code Online (Sandbox Code Playgroud) 我有OnItemTouchListener的回收视图,每个回收器都有一个带onclick事件的按钮.
我希望点击按钮事件工作后,但OnItemTouchListener工作.
请帮忙.我的代码.
public class RecyclerViewTouchListener implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
private ClickListener clickListener;
public RecyclerViewTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
this.clickListener=clickListener;
gestureDetector=new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
@SuppressWarnings("deprecation")
@Override
public boolean onSingleTapUp(MotionEvent e) {
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child!=null && clickListener!=null){
clickListener.OnClick(child,recyclerView.getChildPosition(child));
}
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
//noinspection deprecation
clickListener.OnClick(child, rv.getChildPosition(child)); …Run Code Online (Sandbox Code Playgroud) 我是Android新手.我想水平放置4个按钮,左右两侧边距相等,如下面的线框图所示:
我在Google和Stackoverflow上搜索了很多.我试着设置android:layout_weight ="1".但它只从左侧设定相同的余量.我想在两侧和多个屏幕布局上设置它.我想知道应该为此应用哪些布局和属性.我在Android工作室使用,大多使用拖放方法进行设计.
目前我的XML布局如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/frameLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:id="@+id/relativeLayout">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/b3"
android:layout_gravity="left|center_vertical"
android:onClick="buttonThree"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/b5"
android:layout_gravity="left|center_vertical"
android:onClick="buttonFive"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b3"
android:layout_toEndOf="@+id/b3"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:layout_weight="1"
android:width="0dp"
android:layout_alignParentBottom="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/b7"
android:layout_gravity="left|center_vertical"
android:onClick="buttonSeven"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b5"
android:layout_toEndOf="@+id/b5"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/b9"
android:layout_gravity="left|center_vertical"
android:onClick="buttonNine"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/b7"
android:layout_toEndOf="@+id/b7"
android:layout_alignParentRight="false"
android:layout_weight="1"
android:width="0dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我的目标是让我的按钮灵活,取决于我的组合框的当前值,但问题是当我在该特定事件上运行我的程序它冻结,我的语法有问题或我的电脑只是慢?
private void cmbOperation_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (string)cmbOperation.SelectedItem;
while (selected == "ADD")
{
txtID.ReadOnly = true;
txtLName.ReadOnly = false;
txtFName.ReadOnly = false;
txtMI.ReadOnly = false;
txtGender.ReadOnly = false;
txtAge.ReadOnly = false;
txtContact.ReadOnly = false;
btnOperate.Text = "ADD CLIENT";
}
}
private void btnOperation_Clicked(object sender, EventArgs e)
{
if (cmbOperation.SelectedItem.Equals("ADD"))
{
string constring = "datasource=localhost;port3306;username=root";
string Query = "insert into mybusiness.client_list (LastName,FirstName,MI,Gender,Age,Contact) values('" + this.txtLName.Text + "','" + this.txtFName.Text + "','" + this.txtMI.Text + "','" + this.txtGender.Text …Run Code Online (Sandbox Code Playgroud) 我想使用单击按钮在选择特定div /表中的所有复选框和取消选中所有复选框之间切换.此外,我希望链接/或按钮将名称更改为"全选"和"取消全选".我已经看到类似的答案使用复选框或两个不同的按钮点击,但没有这个.我会使用jquery保持简单和简短.
HTML
<body>
<div id="main">
<div id="first">
<h1>Check & Uncheck All Options</h1>
<p>Check & Uncheck All Options by Button</p>
<input id="checkAll" type="button" value="Check/Uncheck All ">
<div class="button">
<input class="first" id="Item 1" name="option1" type="checkbox">
<label class="label1" for="Item 1">Item 1</label>
<input class="first" id="Item 2" name="option1" type="checkbox">
<label class="label1" for="Item 2">Item 2</label>
<input class="first" id="Item 3" name="option1" type="checkbox">
<label class="label1" for="Item 3">Item 3</label>
<input class="first" id="Item 4" name="option1" type="checkbox">
<label class="label1" for="Item 4">Item 4</label>
</div>
</body>Run Code Online (Sandbox Code Playgroud)
在我的recyclerview客户适配器类中,我在单个项目中的每个按钮上添加了单击侦听器.但是,我需要添加点击监听器并且这样做的按钮很少,因为我有大约3-4个听众,所以我的代码很长.我想知道是否可以缩短点击监听器代码?在我研究这个问题的过程中,我遇到了lambda表达式,但是这些表达式在客户适配器中不起作用,或者我似乎无法让它们正常工作.
这是我使用atm的一个例子:工作正常,但是,我有4个,所以我想尽可能地减少代码;
myHolder.button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Do something
}
});
Run Code Online (Sandbox Code Playgroud)
从研究我尝试了这个:
myHolder.button.setOnClickListener(view -> button.setText("Working"));
Run Code Online (Sandbox Code Playgroud)
此代码提供错误说明:此语言级别不支持lambda表达式
我也试过这个:
myHolder.button.setOnClickListener((View v) -> {
//Do something
});
Run Code Online (Sandbox Code Playgroud)
它给出了与上面相同的错误.
还有其他方法可以缩短代码吗?
你能帮忙的话,我会很高兴.谢谢.
编辑:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId 'com.project.example'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "6.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
Run Code Online (Sandbox Code Playgroud)
.....依赖
我编写了一个程序,用户可以使用该程序绘制形状,将实际按钮和其他工具放在窗体上并使它们处于活动状态.但是,我注意到这种形式的TButton和设计模式中的TButton的外观有很大不同.看看下面的图片.
这个按钮来自我的程序,图像正下方是我在此表单上创建此按钮的方式:

constructor TMakerButton.Create(r:TRect;form:TForm);
begin
inherited Create(r,form);
myType := totButton;
name := 'Button';
caption := 'Button';
lines := TStringList.Create;
lines.Clear;
button := TButton.Create(form);
button.Parent := form;
button.caption := string(caption);
button.Tag := LongInt(Self);
if form is TMakerFrm then
begin
button.Enabled := false;
end;
button.OnClick := ButtonClick;
button.OnMouseMove := ButtonMove;
myControl := button;
with bounds do
button.SetBounds(left,top,right-left,bottom-top);
end;
Run Code Online (Sandbox Code Playgroud)
这是delphi编译器中设计模式中的TButton.看看它如何看起来像具有抛光玻璃外观的3D:
有趣的是,我的程序按钮和delphi编译器的基类是TButton所以,为什么它们看起来如此不同以及如何使我的Button看起来一样?