我正在使用 AlertDialog 要求用户在长按视图时输入数值。这使用 Android 软键盘。为了获得更好的用户体验,我希望键盘“Enter”按钮以编程方式单击警报对话框的肯定按钮并运行它的 onClick。这真的很尴尬,因为我在对话框对象中找不到任何对肯定按钮的引用。代码来说明:
customStakeView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Custom Stake");
customStakeSet = false;
// Set up the input
final EditText input = new EditText(context);
input.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
// Specify the type of input expected;
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
if(!input.getText().toString().equals("")){
switch (keyCode){
case KeyEvent.KEYCODE_ENTER:
//Positive Button Outcome
}
}
}
return false;
}
});
builder.setView(input);
// Set …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 JPanel 上绘制一些简单的形状,但遇到一些困难。如果这个问题之前似乎已经得到解答,但其他答案似乎没有帮助,我们深表歉意。
我遵循了一个简单的教程,并成功地将一些基本形状绘制到 JFrame 上,但是当我将代码移动到扩展 JPanel 的新类中时,屏幕上没有显示任何内容。
public class TestingGraphics extends JFrame{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new TestingGraphics();
}
public TestingGraphics(){
this.setSize(1000,1000);
this.setPreferredSize(new Dimension(1000,1000));
this.setTitle("Drawing tings");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(new TestingPanelGraphics(), BorderLayout.CENTER);
this.setVisible(true);
}
public class TestingPanelGraphics extends JPanel {
public TestingPanelGraphics(){
this.setSize(1000,1000);
this.setPreferredSize(new Dimension(1000,1000));
this.add(new DrawStuff(), BorderLayout.CENTER);
revalidate();
repaint();
this.setVisible(true); //probably not necessary
}
private class DrawStuff extends JComponent{
@Override
protected void paintComponent(Graphics …Run Code Online (Sandbox Code Playgroud) 我已从 Azure Devops 用户界面生成了个人访问令牌,但无法使用它向 Devops API 发出请求。
我尝试了许多不同的标头字段,但我总是被重定向到登录页面,就好像我没有经过身份验证一样。
token = #Token generated on Devops project page
token_bytes = token.encode('utf-8')
token64 = base64.b64encode(token_bytes)
authorization_string = "basic " + str(token64)
repo_endpoint_url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.1".format(organization=organization, project=project)
headers = {"Content-Type" : "application/json", "Authorization" : authorization_string}
response = requests.get(repo_endpoint_url, headers)
Run Code Online (Sandbox Code Playgroud)
响应始终为 203,登录页面为 HTML。如果标头中没有访问令牌,这就是我期望看到的内容。
我尝试过使用“Bearer”而不是“basic”,我尝试过添加 {username}:{token} 以及许多其他小调整。
我究竟做错了什么?
python request access-token azure-devops azure-devops-rest-api
java ×2
access-token ×1
android ×1
awt ×1
azure-devops ×1
graphics ×1
jpanel ×1
python ×1
request ×1
swing ×1