在Kotlin中是否可以创建一个实现某个接口的匿名类,并且只实现您需要的功能?例如,我想创建一个实现AnimationListener有3个方法的类:
如果我只想使用onAnimationEnd回调,我可以这样做吗?
object : AnimationListener {
override fun onAnimationEnd() {
//my implementation
}
}
Run Code Online (Sandbox Code Playgroud)
我在Java中完成此操作的方法是创建一个实现接口的类,只需创建该类的匿名类并覆盖我需要的方法.我希望Kotlin有一个更好,更简洁的方法.
我正在尝试创建一个包含字节数组的Parcelable类.我一直在尝试各种各样的事情,但是如果我想把这个问题放在我的意图上,它似乎仍然失败了.
public class Car implements Parcelable{
private String numberPlate;
private String objectId;
private byte[] photo;
private String type;
private ParseGeoPoint location;
private ParseUser owner;
private String brand;
private double pricePerHour;
private double pricePerKm;
public static final String TYPES[] = {"Cabrio", "Van", "SUV", "Station", "Sedan", "City", "Different"};
public Car(String numberPlate, byte[] bs, String type, ParseGeoPoint location, String brand) {
this.numberPlate = numberPlate;
this.photo = bs;
this.type = type;
this.brand = brand;
this.setLocation(location);
this.owner = ParseUser.getCurrentUser();
}
public Car(Parcel in){
readFromParcel(in);
} …Run Code Online (Sandbox Code Playgroud) 我在使用Java Swing时遇到了一些麻烦.我正在尝试使用顶部的控制面板制作一个框架,其中包含一些按钮.以下我希望JTable显示
我一直在尝试,但桌子没有显示.如果我删除顶部的controlPanel,它有时显示,有时不显示.我在我的JTable的构造函数中使用的代码在同一个应用程序中提供,因此它没有网络错误
public ServerMainFrame(GuiController gc){
this.gc = gc;
initGUI();
}
private void initGUI() {
System.out.println("initiating GUI");
createFrame();
addContentPanel();
addControls();
//openPopUpServerSettings();
addSongTable();
}
private void createFrame()
{
this.setTitle("AudioBuddy 0.1");
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(800, 600);
this.setResizable(false);
this.setLocationRelativeTo(null);
}
private void addContentPanel()
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.setSize(new Dimension(800, 600));
this.setContentPane(p);
}
private void addControls()
{
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBorder(BorderFactory.createLineBorder(Color.black));
controlPanel.setSize(700,100);
// Buttons
JButton play = new JButton("Play");
JButton pause = new JButton("Pause");
JButton stop = …Run Code Online (Sandbox Code Playgroud) 我正在构建一个新的InfoWindow(google maps api v2),我正在尝试让我的布局变得完美.该布局的一部分是这样的:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtInfoWindowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ff000000"
android:textSize="14dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/txtInfoWindowObstacles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLength="32"
android:lines="1"
android:singleLine="true"
android:textColor="#ff7f7f7f"
android:textSize="14dp"/>
Run Code Online (Sandbox Code Playgroud)
现在,问题在于android:ellipsize="end".
它应该在最后绘制三个点,但它不会那样做.现在我得到这样的东西:
TextTextTextTextTe
Run Code Online (Sandbox Code Playgroud)
而不是这个:
TextTextTextTextTe...
Run Code Online (Sandbox Code Playgroud)
我认为它与我正在使用layout_width ="wrap_content"的事实有关.但我需要这个,因为我使用的是LinearLayout
else if (v.getId() == R.id.update) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
URL url = new URL("http://darkliteempire.gaming.multiplay.co.uk/testdownload.txt");
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
//set the path where we want to save the file
//in this case, going to save it on the root directory of the
//sd card.
File SDCardRoot = new File("/sdcard/"+"download/");
//create a new file, specifying the path, and the filename …Run Code Online (Sandbox Code Playgroud) 我通过覆盖onDraw方法并将其翻转90度来制作垂直SeekBar.现在我需要将它放在ScrollView中.
实际的布局结构是
<ScrollView>
<RelativeLayout>
...
<LinearLayout>
<com.mypackage.VerticalSeekBar/>
Run Code Online (Sandbox Code Playgroud)
是否可以确保ScrollView无法获取我的搜索栏的触摸事件?
我有一些颜色定义/values/colors.xml.
我如何以编程方式获取某种颜色的id,例如,R.color.my_color如果我知道颜色的名称.
我试图使用RxDart将Firestore中的两个流合并到一个流中,但它只返回一个流的结果
Stream getData() {
Stream stream1 = Firestore.instance.collection('test').where('type', isEqualTo: 'type1').snapshots();
Stream stream2 = Firestore.instance.collection('test').where('type', isEqualTo: 'type2').snapshots();
return Observable.merge(([stream2, stream1]));
}
Run Code Online (Sandbox Code Playgroud)